Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep NeverType isExplicit-flag in TypeCombinator::intersect() #2112

Merged
merged 1 commit into from Dec 15, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Dec 14, 2022

inspired by #2110 where we addd logic based on NeverType explicitness, I figured it would be helpful if the TypeCombinator would keep the exlicitness, instead of create a new non-explicit NeverType every-time it combines NeverTypes'.

Before this PR there was no way to differentiate between NeverType explicit and implicit - I therefore added the same "hack" we use to differentiate explicit and implicit MixedType in tests.


this could be followed up by changes in e.g.

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
return new NeverType();
}
where we also loose the explicitness (several occurences in the InitializerExprTypeResolver with this pattern)

@@ -946,7 +946,7 @@ public static function intersect(Type ...$types): Type
$valueType = $types[$j]->getValueType();
$newValueType = self::intersect($types[$i]->getOffsetValueType($offsetType), $valueType);
if ($newValueType instanceof NeverType) {
return new NeverType();
Copy link
Contributor Author

@staabm staabm Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines dropped the explicitness flag before this PR

Comment on lines +3510 to +3517
[
[
new NeverType(true),
new IntegerType(),
],
NeverType::class,
'*NEVER*=explicit',
],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we have a test which now returns a explicit NeverType. all other tests where adjusted to compensate the additional implicit information in the description. no changes regarding the typtes itself.

@ondrejmirtes ondrejmirtes merged commit b2e1a09 into phpstan:1.9.x Dec 15, 2022
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants