psalm: [Templating] assertig that a `string` is `non-empty-string` using a generic validator results in a *false* redundant condition error

example: https://psalm.dev/r/ae244c6b02

If we replace Type<non-empty-string> with a concrete class, we get no issues: https://psalm.dev/r/515024a452

investigating further, this seems to be related to covariant templating: https://psalm.dev/r/b0278b0493

whatever psalm changed in 4.10, completely broke PSL Type component, we now have the choice to either go back to using @template and not be able to create a union type, and any other array type, or keep as is and remove matches validator ( both options are BC breaking, currently down stream users are getting a type error either in the constructor ( for PSL < 1.8 ), or when using matches ( PSL >= 1.8, which uses covariant )

ref: https://github.com/azjezz/psl/issues/227 ref: https://github.com/azjezz/psl/discussions/231 ref: https://github.com/azjezz/psl/issues/212 ref: https://github.com/azjezz/psl/pull/214

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I think the covariant issue is not a problem, however, i also don’t think matches should fail in this case, i will try to give it a try and fix it 😃

This works in 4.4.1, and fails in 4.10: https://psalm.dev/r/5aee8f5518

to fix this in 4.10, we have to replace @template with @template-covariant, however, that’s when ->matches($x) starts to fail.