Repository navigation
Keep subclasses of string, int and float apart in unions - #7215
Merged
Merged
Conversation
StringType::getStringRefinement() and IntegerType/FloatType::toExactNumberSet() now describe only the exact class. A subclass defined by an extension, as Larastan's model property of X, may hold fewer values than its parent, so ScalarUnion merged two of them by their cells or numbers and kept only the first: model property of User|model property of Account became model property of User. They now get null and are unioned by isSuperTypeOf(). ConstantIntegerType, ConstantFloatType and FloatRangeType, whose numbers are exact, override toExactNumberSet() to keep theirs. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4a-e25b-74f0-9147-bfb3ae88286a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 47ef9f6,
TypeCombinatormerges strings bygetStringRefinement()and numbers bytoExactNumberSet(). Subclasses inherited those fromStringType,IntegerTypeandFloatType, so two unrelated subclasses defined by an extension looked identical and the first one won:model property of User|model property of Accountbecamemodel property of User, depending on operand order (Larastan, phpstan-laravel and librenms integration tests).The three base methods now describe only the exact class; any other subclass returns null and is unioned through
isSuperTypeOf().ConstantIntegerType,ConstantFloatTypeandFloatRangeTypeoverridetoExactNumberSet()to keep their exact numbers. The native mirrors in turbo-ext do the same.New
TypeCombinatorTestcases fail on 2.3.x and pass here. The full suite passes with and without the extension.Closes phpstan/phpstan#15859
Amp thread: https://ampcode.com/threads/T-01a21c4a-e25b-74f0-9147-bfb3ae88286a