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

Fix is_subclass_of(string, string) generates invalid prediction

Open Bl00D4NGEL opened this issue 2 years ago • 4 comments

Fixes https://github.com/phpstan/phpstan/issues/3979

Bl00D4NGEL avatar Aug 14 '22 22:08 Bl00D4NGEL

Hi, I'm sorry, this isn't the right fix. We should look into why is this reported. This code sample goes shows more about the types involved (class-string and non-falsy-string): https://phpstan.org/r/4399bb2a-cf2b-4038-9716-97cac1e647d4

My guess is that the bug is rather in IsSubclassOfFunctionTypeSpecifyingExtension.

ondrejmirtes avatar Aug 15 '22 12:08 ondrejmirtes

Hi @ondrejmirtes thanks for the hint!

I looked into IsSubclassOfFunctionTypeSpecifyingExtension and tried to make changes that hopefully fit a little better. Still I am not sure if this is the fix you were looking for as this is still somewhat ignoring the "root cause" so to say.

If this still isn't sufficient I'd appreciate some more directions as to where the problem should be fixed :)

Bl00D4NGEL avatar Aug 15 '22 16:08 Bl00D4NGEL

I'd say the extension doesn't add any value and only confuses the analyser for class-string and non-falsy-string input types. So we'd have to identify for what types it adds some value for type inference, and in other cases just return empty new SpecifiedTypes().

ondrejmirtes avatar Aug 17 '22 12:08 ondrejmirtes

I'm afraid I don't quite understand what you're trying to say or want me to change.

I'd say the extension doesn't add any value

Does this refer to my changes or to the IsSubclassOfFunctionTypeSpecifyingExtension itself?

So we'd have to identify for what types it adds some value for type inference

How would I go about that? Is there some guideline/example I could base this off?

and in other cases just return empty new SpecifiedTypes().

So basically this would be "check if this extension can add valueable types", if not return SpecifiedTypes, else return valueable types?

Bl00D4NGEL avatar Aug 22 '22 07:08 Bl00D4NGEL

Hi, I'm cleaning up old and stale PRs. Please send a new PR if you're still interested, thanks.

ondrejmirtes avatar Oct 16 '22 10:10 ondrejmirtes