phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

add Type::isError method

Open canvural opened this issue 1 month ago • 6 comments

This one does not add too much value, but I just didn't want to do instanceof ErrorType in my extensions 😄

canvural avatar Nov 06 '25 15:11 canvural

Do you also feel like doing isNever() + isExplicitNever()? :)

ondrejmirtes avatar Nov 07 '25 12:11 ondrejmirtes

Do you also feel like doing isNever() + isExplicitNever()? :)

Didn't ever need that I guess, but sure I can. In a separate PR?

canvural avatar Nov 07 '25 13:11 canvural

The mutations look valid, but I don't know how I can change them in bulk.

Edit: I guess $type instanceof ErrorType could be !$type->isError()->no() and !$type instanceof ErrorType can be $type->isError()->no() ?

canvural avatar Nov 10 '25 10:11 canvural

I'm not sure how to cover the mutations with tests here. i'm more concerned about the things the issue bot found https://github.com/phpstan/phpstan-src/actions/runs/19215786400, I'm not sure why that's happening.

ondrejmirtes avatar Nov 11 '25 07:11 ondrejmirtes

just a gut feeling in case the 2 above comments regarding behaviour changes are not valid:

another source of problems could be

  • class ErrorType extends MixedType
  • class TemplateMixedType extends MixedType

because MixedType - because of substraction logic - might lead to a Maybe.

staabm avatar Nov 11 '25 08:11 staabm

In #4547

$expressionType instanceof NeverType

by

!$expressionType->isNever()->no()

But here you're replacing

$type instanceof ErrorType

by

$type->isError()->yes()

How did you choose ? I feel like we should have consistency...

Yeah we should have consistency. In the isNever PR I did it that way to see how the mutation testing will behave. But honestly I'd rather have $type->isError()->yes() everywhere, it's much easier to understand. So I'll change the other PR later.

canvural avatar Nov 12 '25 23:11 canvural