Repository navigation
Add TemplateIntegerRangeType, TemplateFloatRangeType and TemplateConstantFloatType - #7290
Merged
Merged
Conversation
…tantFloatType Template types bounded by an integer range, a float range or a float constant were created as TemplateIntegerType or TemplateFloatType, which kept the bound but behaved as plain int or float, and TemplateTypeCheck reported these bounds as not supported. Each now has its own template class over the bound's type, so comparisons, arithmetic and abs() use the range or the constant. A template range is an unknown part of its range, not all of it: the range types no longer merge it in tryUnion()/tryIntersect() or remove it as a whole in tryRemove(), UnionType::isSuperTypeOf() no longer hands it back to isSubTypeOf(), and FiniteTypesRemoveRule no longer removes all the values of a template that has several of them. Amp-Thread-ID: https://ampcode.com/threads/T-01a23674-8e36-7696-8d80-30a0668f254a
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.
Template types bounded by
int<a, b>,float<a, b>or a float constant were created asTemplateIntegerType/TemplateFloatType. They kept the bound but behaved as plainint/float, andTemplateTypeCheckreported these bounds as not supported. This addsTemplateIntegerRangeType,TemplateFloatRangeTypeandTemplateConstantFloatType, followingTemplateConstantIntegerType/TemplateFloatType, with their turbo-ext mirrors.With
@template T of int<0, 5>:$t > 10isfalse(wasbool),$t + 1isint<1, 6>(wasint),abs($t)isT.Things that needed care because a template range is now an
IntegerRangeType/FloatRangeType:IntegerRangeTypeandFloatRangeTypeconstructors areprotectedinstead ofprivate.tryUnion()/tryIntersect()(which dropped the template) or remove it as a whole intryRemove()(which was unsound:int<0, 9>minusT of int<0, 5>gaveint<6, 9>).UnionType::isSuperTypeOf()no longer hands a template range back toisSubTypeOf()(infinite recursion), likeTemplateIterableType.FiniteTypesRemoveRuleno longer removes every value of a template that has several. This also fixesboolminusT of boolbeingnever.UndecidedComparisonCompoundTypeTrait: the range's own comparisons hold for any subset of it.Two expectations in
bug-15714.phpbecame more precise (abs()of a negativeT of intisint<1, max>,abs()ofT of float<0, 1>isT).Closes phpstan/phpstan#10660