diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 21a2dbc7f5a..3ae627c59a8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1237,6 +1237,18 @@ parameters: count: 3 path: src/Type/Generic/TemplateConstantArrayType.php + - + rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. + identifier: phpstanApi.instanceofType + count: 3 + path: src/Type/Generic/TemplateConstantFloatType.php + + - + rawMessage: 'Method PHPStan\Type\Generic\TemplateConstantFloatType::toPhpDocNode() should return PHPStan\PhpDocParser\Ast\Type\ConstTypeNode but returns PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode.' + identifier: return.type + count: 1 + path: src/Type/Generic/TemplateConstantFloatType.php + - rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. identifier: phpstanApi.instanceofType @@ -1255,6 +1267,12 @@ parameters: count: 3 path: src/Type/Generic/TemplateConstantStringType.php + - + rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. + identifier: phpstanApi.instanceofType + count: 3 + path: src/Type/Generic/TemplateFloatRangeType.php + - rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. identifier: phpstanApi.instanceofType @@ -1267,6 +1285,12 @@ parameters: count: 3 path: src/Type/Generic/TemplateGenericObjectType.php + - + rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. + identifier: phpstanApi.instanceofType + count: 3 + path: src/Type/Generic/TemplateIntegerRangeType.php + - rawMessage: Doing instanceof PHPStan\Type\IntersectionType is error-prone and deprecated. identifier: phpstanApi.instanceofType diff --git a/src/Rules/Generics/TemplateTypeCheck.php b/src/Rules/Generics/TemplateTypeCheck.php index 60bbadcaffc..e1441152b51 100644 --- a/src/Rules/Generics/TemplateTypeCheck.php +++ b/src/Rules/Generics/TemplateTypeCheck.php @@ -17,12 +17,15 @@ use PHPStan\Type\ArrayType; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; +use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\FloatRangeType; use PHPStan\Type\FloatType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\Generic\TemplateTypeScope; +use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntegerType; use PHPStan\Type\IntersectionType; use PHPStan\Type\IterableType; @@ -143,7 +146,10 @@ public function check( && $boundTypeClass !== StringType::class && $boundTypeClass !== ConstantIntegerType::class && $boundTypeClass !== IntegerType::class + && $boundTypeClass !== IntegerRangeType::class + && $boundTypeClass !== ConstantFloatType::class && $boundTypeClass !== FloatType::class + && $boundTypeClass !== FloatRangeType::class && $boundTypeClass !== BooleanType::class && $boundTypeClass !== ObjectWithoutClassType::class && $boundTypeClass !== ObjectType::class diff --git a/src/Type/Combinator/FiniteTypesRemoveRule.php b/src/Type/Combinator/FiniteTypesRemoveRule.php index 4733524fca7..981b4d443bb 100644 --- a/src/Type/Combinator/FiniteTypesRemoveRule.php +++ b/src/Type/Combinator/FiniteTypesRemoveRule.php @@ -2,6 +2,7 @@ namespace PHPStan\Type\Combinator; +use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\NeverType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; @@ -27,6 +28,11 @@ public function tryRemove(Type $fromType, Type $typeToRemove): ?Type return null; } + // a template of several values stands for an unknown part of them, not for all of them + if ($typeToRemove instanceof TemplateType && count($finiteTypesToRemove) > 1) { + return null; + } + $result = []; foreach ($fromFiniteTypes as $finiteType) { foreach ($finiteTypesToRemove as $finiteTypeToRemove) { diff --git a/src/Type/FloatRangeType.php b/src/Type/FloatRangeType.php index 1ff7dc888a9..af69b618347 100644 --- a/src/Type/FloatRangeType.php +++ b/src/Type/FloatRangeType.php @@ -16,6 +16,7 @@ use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\Generic\TemplateFloatRangeType; use function array_map; use function get_class; use function is_finite; @@ -49,7 +50,7 @@ class FloatRangeType extends FloatType implements CompoundType { - private function __construct(private float $min, private float $max) + protected function __construct(private float $min, private float $max) { parent::__construct(); } @@ -484,6 +485,11 @@ public function toAbsoluteNumber(): Type */ public function tryIntersect(Type $otherType): ?Type { + // a template stands for an unknown part of its range, not for all of it + if ($otherType instanceof TemplateFloatRangeType) { + return null; + } + $bounds = self::getOrdinalBounds($otherType); if ($bounds !== null) { [$otherMin, $otherMax] = $bounds; @@ -515,6 +521,10 @@ public function tryRemove(Type $typeToRemove): ?Type return new NeverType(); } + if ($typeToRemove instanceof TemplateFloatRangeType) { + return null; + } + $bounds = self::getOrdinalBounds($typeToRemove); if ($bounds === null) { // NAN is in no range diff --git a/src/Type/Generic/TemplateConstantFloatType.php b/src/Type/Generic/TemplateConstantFloatType.php new file mode 100644 index 00000000000..d61009c6efa --- /dev/null +++ b/src/Type/Generic/TemplateConstantFloatType.php @@ -0,0 +1,40 @@ + */ + use TemplateTypeTrait; + use UndecidedComparisonCompoundTypeTrait; + + /** + * @param non-empty-string $name + */ + public function __construct( + TemplateTypeScope $scope, + TemplateTypeStrategy $templateTypeStrategy, + TemplateTypeVariance $templateTypeVariance, + string $name, + ConstantFloatType $bound, + ?Type $default, + ) + { + parent::__construct($bound->getValue()); + $this->scope = $scope; + $this->strategy = $templateTypeStrategy; + $this->variance = $templateTypeVariance; + $this->name = $name; + $this->bound = $bound; + $this->default = $default; + } + +} diff --git a/src/Type/Generic/TemplateFloatRangeType.php b/src/Type/Generic/TemplateFloatRangeType.php new file mode 100644 index 00000000000..757667cb7a1 --- /dev/null +++ b/src/Type/Generic/TemplateFloatRangeType.php @@ -0,0 +1,49 @@ + */ + use TemplateTypeTrait; + + /** + * @param non-empty-string $name + */ + public function __construct( + TemplateTypeScope $scope, + TemplateTypeStrategy $templateTypeStrategy, + TemplateTypeVariance $templateTypeVariance, + string $name, + FloatRangeType $bound, + ?Type $default, + ) + { + parent::__construct($bound->getMin(), $bound->getMax()); + $this->scope = $scope; + $this->strategy = $templateTypeStrategy; + $this->variance = $templateTypeVariance; + $this->name = $name; + $this->bound = $bound; + $this->default = $default; + } + + /** A T is an unknown part of its range: merged with another range it would no longer be a T. */ + public function tryUnion(Type $otherType): ?Type + { + return null; + } + + public function tryIntersect(Type $otherType): ?Type + { + return null; + } + +} diff --git a/src/Type/Generic/TemplateIntegerRangeType.php b/src/Type/Generic/TemplateIntegerRangeType.php new file mode 100644 index 00000000000..fd279c4a854 --- /dev/null +++ b/src/Type/Generic/TemplateIntegerRangeType.php @@ -0,0 +1,49 @@ + */ + use TemplateTypeTrait; + + /** + * @param non-empty-string $name + */ + public function __construct( + TemplateTypeScope $scope, + TemplateTypeStrategy $templateTypeStrategy, + TemplateTypeVariance $templateTypeVariance, + string $name, + IntegerRangeType $bound, + ?Type $default, + ) + { + parent::__construct($bound->getMin(), $bound->getMax()); + $this->scope = $scope; + $this->strategy = $templateTypeStrategy; + $this->variance = $templateTypeVariance; + $this->name = $name; + $this->bound = $bound; + $this->default = $default; + } + + /** A T is an unknown part of its range: merged with another range it would no longer be a T. */ + public function tryUnion(Type $otherType): ?Type + { + return null; + } + + public function tryIntersect(Type $otherType): ?Type + { + return null; + } + +} diff --git a/src/Type/Generic/TemplateTypeFactory.php b/src/Type/Generic/TemplateTypeFactory.php index 90b3e968956..08ec424e5f6 100644 --- a/src/Type/Generic/TemplateTypeFactory.php +++ b/src/Type/Generic/TemplateTypeFactory.php @@ -8,8 +8,10 @@ use PHPStan\Type\BenevolentUnionType; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; +use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\FloatRangeType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntegerType; @@ -77,7 +79,11 @@ public static function create(TemplateTypeScope $scope, string $name, ?Type $bou return new TemplateConstantStringType($scope, $strategy, $variance, $name, $bound, $default); } - if ($bound instanceof IntegerType && ($boundClass === IntegerType::class || $bound instanceof IntegerRangeType || $bound instanceof TemplateType)) { + if ($bound instanceof IntegerRangeType && ($boundClass === IntegerRangeType::class || $bound instanceof TemplateType)) { + return new TemplateIntegerRangeType($scope, $strategy, $variance, $name, $bound, $default); + } + + if ($bound instanceof IntegerType && ($boundClass === IntegerType::class || $bound instanceof TemplateType)) { return new TemplateIntegerType($scope, $strategy, $variance, $name, $bound, $default); } @@ -85,10 +91,15 @@ public static function create(TemplateTypeScope $scope, string $name, ?Type $bou return new TemplateConstantIntegerType($scope, $strategy, $variance, $name, $bound, $default); } - // Catches plain FloatType and the float subtypes that narrowing a bound - // produces, a FloatRangeType or a ConstantFloatType, neither of which has a - // dedicated Template* class to fall into. - if ($bound instanceof FloatType) { + if ($bound instanceof FloatRangeType && ($boundClass === FloatRangeType::class || $bound instanceof TemplateType)) { + return new TemplateFloatRangeType($scope, $strategy, $variance, $name, $bound, $default); + } + + if ($bound instanceof ConstantFloatType && ($boundClass === ConstantFloatType::class || $bound instanceof TemplateType)) { + return new TemplateConstantFloatType($scope, $strategy, $variance, $name, $bound, $default); + } + + if ($bound instanceof FloatType && ($boundClass === FloatType::class || $bound instanceof TemplateType)) { return new TemplateFloatType($scope, $strategy, $variance, $name, $bound, $default); } diff --git a/src/Type/IntegerRangeType.php b/src/Type/IntegerRangeType.php index 3170f9b65cd..6fdfbafb523 100644 --- a/src/Type/IntegerRangeType.php +++ b/src/Type/IntegerRangeType.php @@ -16,6 +16,7 @@ use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\Generic\TemplateIntegerRangeType; use PHPStan\Type\Traits\OperatorTypeTrait; use function array_filter; use function array_map; @@ -42,7 +43,7 @@ class IntegerRangeType extends IntegerType implements CompoundType use OperatorTypeTrait; - private function __construct(private ?int $min, private ?int $max) + protected function __construct(private ?int $min, private ?int $max) { parent::__construct(); assert($min === null || $max === null || $min <= $max); @@ -640,6 +641,11 @@ public function toString(): Type */ public function tryUnion(Type $otherType): ?Type { + // a template stands for an unknown part of its range, not for all of it + if ($otherType instanceof TemplateIntegerRangeType) { + return null; + } + if ($otherType instanceof self || $otherType instanceof ConstantIntegerType) { if ($otherType instanceof self) { $otherMin = $otherType->min; @@ -673,6 +679,10 @@ public function tryUnion(Type $otherType): ?Type */ public function tryIntersect(Type $otherType): ?Type { + if ($otherType instanceof TemplateIntegerRangeType) { + return null; + } + if ($otherType instanceof self || $otherType instanceof ConstantIntegerType) { if ($otherType instanceof self) { $otherMin = $otherType->min; @@ -722,6 +732,10 @@ public function tryRemove(Type $typeToRemove): ?Type return new NeverType(); } + if ($typeToRemove instanceof TemplateIntegerRangeType) { + return null; + } + if ($typeToRemove instanceof self || $typeToRemove instanceof ConstantIntegerType) { if ($typeToRemove instanceof self) { $removeMin = $typeToRemove->min; diff --git a/src/Type/IntegerType.php b/src/Type/IntegerType.php index ddf4040dff0..ed673ba8819 100644 --- a/src/Type/IntegerType.php +++ b/src/Type/IntegerType.php @@ -12,6 +12,7 @@ use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\Generic\TemplateIntegerRangeType; use PHPStan\Type\Traits\NonArrayTypeTrait; use PHPStan\Type\Traits\NonCallableTypeTrait; use PHPStan\Type\Traits\NonGeneralizableTypeTrait; @@ -188,6 +189,11 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType public function tryRemove(Type $typeToRemove): ?Type { + // a template stands for an unknown part of its range, not for all of it + if ($typeToRemove instanceof TemplateIntegerRangeType) { + return null; + } + if ($typeToRemove instanceof IntegerRangeType || $typeToRemove instanceof ConstantIntegerType) { if ($typeToRemove instanceof IntegerRangeType) { $removeValueMin = $typeToRemove->getMin(); diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 2dcfceef315..fc5ef6c89a3 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -29,6 +29,7 @@ use PHPStan\Type\Enum\EnumCaseObjectType; use PHPStan\Type\Generic\AbsorbedTemplateArgumentType; use PHPStan\Type\Generic\GenericClassStringType; +use PHPStan\Type\Generic\TemplateIntegerRangeType; use PHPStan\Type\Generic\TemplateIterableType; use PHPStan\Type\Generic\TemplateMixedType; use PHPStan\Type\Generic\TemplateType; @@ -389,7 +390,7 @@ public function isSuperTypeOf(Type $otherType): IsSuperTypeOfResult ($otherType instanceof self && !$otherType instanceof TemplateUnionType) || ($otherType instanceof IterableType && !$otherType instanceof TemplateIterableType) || $otherType instanceof NeverType - || $otherType instanceof IntegerRangeType + || ($otherType instanceof IntegerRangeType && !$otherType instanceof TemplateIntegerRangeType) // stands for its delegate, which can itself be a union || $otherType instanceof UnresolvedTemplateArgumentType // unfolds to its members, each of which another member here can hold diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 0050b34d316..04ffce774b0 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1903,6 +1903,12 @@ public function testBug15754(): void $this->assertSame(23, $errors[1]->getLine()); } + public function testBug10660(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-10660.php'); + $this->assertNoErrors($errors); + } + public function testReflectionMethodOfClassStringOfNonExistentClass(): void { $errors = $this->runAnalyse(__DIR__ . '/data/reflection-method-of-class-string-of-non-existent-class.php'); diff --git a/tests/PHPStan/Analyser/data/bug-10660.php b/tests/PHPStan/Analyser/data/bug-10660.php new file mode 100644 index 00000000000..aa19682664f --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-10660.php @@ -0,0 +1,34 @@ + + * @template TFlags2 of int-mask-of + * @template TFlags3 of int-mask-of + * + * @param TFlags1 $flags1 + * @param TFlags2 $flags2 + * @param TFlags3 $flags3 + */ + public function doSomething(int $flags1, int $flags2, int $flags3): void; +} diff --git a/tests/PHPStan/Analyser/nsrt/bug-15714.php b/tests/PHPStan/Analyser/nsrt/bug-15714.php index 9c1f67c77cc..de985615281 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-15714.php +++ b/tests/PHPStan/Analyser/nsrt/bug-15714.php @@ -82,7 +82,7 @@ function absoluteInt(int $t): int assertType('int<0, max>', abs($t)); if ($t < 0) { - assertType('int<0, max>', abs($t)); + assertType('int<1, max>', abs($t)); } return $t; @@ -139,7 +139,7 @@ function unionBound($t) function rangeBound(float $t): float { assertType('T of float<0.0, 1.0> (function Bug15714\rangeBound(), argument)', $t); - assertType('float<0.0, 1.0>', abs($t)); + assertType('T of float<0.0, 1.0> (function Bug15714\rangeBound(), argument)', abs($t)); return $t; } diff --git a/tests/PHPStan/Analyser/nsrt/template-range-and-constant-float-bound.php b/tests/PHPStan/Analyser/nsrt/template-range-and-constant-float-bound.php new file mode 100644 index 00000000000..bd0b9793569 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/template-range-and-constant-float-bound.php @@ -0,0 +1,122 @@ + + * @param T $t + * @param int<0, 9> $i + */ +function integerRange($t, int $i): void +{ + assertType('T of int<0, 5> (function TemplateRangeAndConstantFloatBound\integerRange(), argument)', $t); + assertType('false', $t > 10); + assertType('true', $t >= 0); + assertType('int<1, 6>', $t + 1); + assertType('T of int<0, 5> (function TemplateRangeAndConstantFloatBound\integerRange(), argument)', abs($t)); + assertType('7|T of int<0, 5> (function TemplateRangeAndConstantFloatBound\integerRange(), argument)', rand(0, 1) ? $t : 7); + assertType('T of int<0, 5> (function TemplateRangeAndConstantFloatBound\integerRange(), argument)|int<6, 9>', rand(0, 1) ? $t : rand(6, 9)); + + if ($i !== $t) { + assertType('int<0, 9>', $i); + } +} + +/** + * @template T of int<0, 5> + * @param T $t + */ +function narrowIntegerRange($t): void +{ + if ($t > 2) { + assertType('T of int<3, 5> (function TemplateRangeAndConstantFloatBound\narrowIntegerRange(), argument)', $t); + } else { + assertType('T of int<0, 2> (function TemplateRangeAndConstantFloatBound\narrowIntegerRange(), argument)', $t); + } +} + +/** + * @template T of float<0, 1> + * @param T $t + * @param float<0, 2> $f + */ +function floatRange($t, float $f): void +{ + assertType('T of float<0.0, 1.0> (function TemplateRangeAndConstantFloatBound\floatRange(), argument)', $t); + assertType('false', $t > 2.0); + assertType('float<0.0, 2.0>', $t * 2); + assertType('0.5|T of float<0.0, 1.0> (function TemplateRangeAndConstantFloatBound\floatRange(), argument)', rand(0, 1) ? $t : 0.5); + + if ($f !== $t) { + assertType('float<0.0, 2.0>', $f); + } +} + +/** + * @template T of float<0, 1> + * @param T $t + */ +function narrowFloatRange($t): void +{ + if ($t > 0.5) { + assertType('T of float<0.5000000000000001, 1.0> (function TemplateRangeAndConstantFloatBound\narrowFloatRange(), argument)', $t); + } else { + assertType('T of float<0.0, 0.5> (function TemplateRangeAndConstantFloatBound\narrowFloatRange(), argument)', $t); + } +} + +/** + * @template T of 1.5 + * @param T $t + */ +function constantFloat($t): void +{ + assertType('T of 1.5 (function TemplateRangeAndConstantFloatBound\constantFloat(), argument)', $t); + assertType('false', $t > 10.0); + assertType('true', $t === 1.5); + assertType('2.5', $t + 1); + assertType('-1.5', -$t); +} + +/** + * @template T of int<0, 5> + * @param T $t + * @return T + */ +function identityIntegerRange($t) +{ + return $t; +} + +/** + * @template T of float<0, 1> + * @param T $t + * @return T + */ +function identityFloatRange($t) +{ + return $t; +} + +/** + * @template T of 1.5 + * @param T $t + * @return T + */ +function identityConstantFloat($t) +{ + return $t; +} + +/** + * @param int<1, 2> $i + */ +function calls(int $i): void +{ + assertType('3', identityIntegerRange(3)); + assertType('int<1, 2>', identityIntegerRange($i)); + assertType('0.5', identityFloatRange(0.5)); + assertType('1.5', identityConstantFloat(1.5)); +} diff --git a/tests/PHPStan/Rules/Generics/data/function-template.php b/tests/PHPStan/Rules/Generics/data/function-template.php index c938c5dff46..3cbf727daaa 100644 --- a/tests/PHPStan/Rules/Generics/data/function-template.php +++ b/tests/PHPStan/Rules/Generics/data/function-template.php @@ -121,3 +121,21 @@ function requiredAfterOptional() { } + +/** @template T of int<0, 5> */ +function integerRangeSupported() +{ + +} + +/** @template T of float<0, 1> */ +function floatRangeSupported() +{ + +} + +/** @template T of 1.5 */ +function constantFloatSupported() +{ + +} diff --git a/turbo-ext/src/FloatRangeType.cpp b/turbo-ext/src/FloatRangeType.cpp index f880c6630ff..50256401ae0 100644 --- a/turbo-ext/src/FloatRangeType.cpp +++ b/turbo-ext/src/FloatRangeType.cpp @@ -39,7 +39,7 @@ class FloatRangeType public: explicit FloatRangeType(zend_object *self) : self(self) {} - /* private __construct(private float $min, private float $max): + /* protected __construct(private float $min, private float $max): * initializes the typed slots; parent::__construct() is FloatType's * empty constructor */ void construct(double min, double max) @@ -622,6 +622,9 @@ class FloatRangeType * plain FloatType, null otherwise; UNDEF = pending exception */ zv::Val tryIntersect(zval *otherType) const { + /* a template stands for an unknown part of its range, not for all of it */ + if (instanceof_function(Z_OBJCE_P(otherType), pt_ce_template_float_range_type)) return zv::Val::null(); + bool found; zend_long otherMin = 0, otherMax = 0; if (UNEXPECTED(!getOrdinalBounds(otherType, found, otherMin, otherMax))) return zv::Val(); @@ -649,6 +652,8 @@ class FloatRangeType /* get_class($typeToRemove) === parent::class */ if (Z_OBJCE_P(typeToRemove) == pt_ce_float_type) return pt_type_new_never_type(); + if (instanceof_function(Z_OBJCE_P(typeToRemove), pt_ce_template_float_range_type)) return zv::Val::null(); + bool found; zend_long removeMin = 0, removeMax = 0; if (UNEXPECTED(!getOrdinalBounds(typeToRemove, found, removeMin, removeMax))) return zv::Val(); diff --git a/turbo-ext/src/IntegerRangeType.cpp b/turbo-ext/src/IntegerRangeType.cpp index 22eadc0d6ba..461002e6ad8 100644 --- a/turbo-ext/src/IntegerRangeType.cpp +++ b/turbo-ext/src/IntegerRangeType.cpp @@ -92,11 +92,12 @@ class IntegerRangeType public: explicit IntegerRangeType(zend_object *self) : self(self) {} - /* private __construct(private ?int $min, private ?int $max): initializes + /* protected __construct(private ?int $min, private ?int $max): initializes * the typed slots; parent::__construct() is IntegerType's empty * constructor. The twin's two assert()s (min <= max, not both null) - * hold for every caller — fromInterval() is the only one and validates - * first — so nothing is asserted here. */ + * hold for every caller — fromInterval() validates first, and + * TemplateIntegerRangeType copies an existing range's bounds — so + * nothing is asserted here. */ void construct(NullableLong min, NullableLong max) { zval *minSlot = OBJ_PROP_NUM(self, slots::min); @@ -820,6 +821,9 @@ class IntegerRangeType * when the union needs a UnionType; UNDEF = pending exception */ zv::Val tryUnion(zval *otherType) const { + /* a template stands for an unknown part of its range, not for all of it */ + if (instanceof_function(Z_OBJCE_P(otherType), pt_ce_template_integer_range_type)) return zv::Val::null(); + NullableLong otherMin = NullableLong::null(), otherMax = NullableLong::null(); bool integerLike; if (UNEXPECTED(!boundsOf(otherType, integerLike, otherMin, otherMax))) return zv::Val(); @@ -848,6 +852,8 @@ class IntegerRangeType * exception */ zv::Val tryIntersect(zval *otherType) const { + if (instanceof_function(Z_OBJCE_P(otherType), pt_ce_template_integer_range_type)) return zv::Val::null(); + NullableLong otherMin = NullableLong::null(), otherMax = NullableLong::null(); bool integerLike; if (UNEXPECTED(!boundsOf(otherType, integerLike, otherMin, otherMax))) return zv::Val(); @@ -893,6 +899,8 @@ class IntegerRangeType /* get_class($typeToRemove) === parent::class */ if (Z_OBJCE_P(typeToRemove) == pt_ce_integer_type) return never(); + if (instanceof_function(Z_OBJCE_P(typeToRemove), pt_ce_template_integer_range_type)) return zv::Val::null(); + NullableLong removeMin = NullableLong::null(), removeMax = NullableLong::null(); bool integerLike; if (UNEXPECTED(!boundsOf(typeToRemove, integerLike, removeMin, removeMax))) return zv::Val(); diff --git a/turbo-ext/src/IntegerType.cpp b/turbo-ext/src/IntegerType.cpp index d13bc615eb3..a73e49ffc74 100644 --- a/turbo-ext/src/IntegerType.cpp +++ b/turbo-ext/src/IntegerType.cpp @@ -158,6 +158,9 @@ class IntegerType * exception */ static zv::Val tryRemove(zval *typeToRemove) { + /* a template stands for an unknown part of its range, not for all of it */ + if (instanceof_function(Z_OBJCE_P(typeToRemove), pt_ce_template_integer_range_type)) return zv::Val::null(); + NullableLong removeValueMin, removeValueMax; if (instanceof_function(Z_OBJCE_P(typeToRemove), pt_ce_integer_range_type)) { if (UNEXPECTED(!pt_integer_range_bounds(Z_OBJ_P(typeToRemove), removeValueMin, removeValueMax))) return zv::Val(); diff --git a/turbo-ext/src/TemplateConstantFloatType.cpp b/turbo-ext/src/TemplateConstantFloatType.cpp new file mode 100644 index 00000000000..9527b28c1af --- /dev/null +++ b/turbo-ext/src/TemplateConstantFloatType.cpp @@ -0,0 +1,85 @@ +/* + * PHPStanTurbo\TemplateConstantFloatType — native implementation of + * PHPStan\Type\Generic\TemplateConstantFloatType. + * + * Declared as PHPStan\Type\Generic\TemplateConstantFloatType itself at activation: + * final, extending the native ConstantFloatType and implementing the PHP + * TemplateType interface. The twin composes TemplateTypeTrait and UndecidedComparisonCompoundTypeTrait + * — the shared registrars in TypeTraits.cpp supply those methods and the + * trait's six slots (after the parent's); the constructor runs + * parent::__construct($bound->getValue()) and then the trait's slot writes. + */ + +#include "TypeTraits.h" +#include "generated/TemplateConstantFloatType.h" + +namespace sigs = ptdecl::TemplateConstantFloatType::sig; + +zend_class_entry *pt_ce_template_constant_float_type = nullptr; + +namespace phpstanturbo { + +/* Mirrors PHPStan\Type\Generic\TemplateConstantFloatType. State lives in the parent's slots + * and the trait's six. */ +class TemplateConstantFloatType +{ +public: + explicit TemplateConstantFloatType(zend_object *self) : self(self) {} + + /* __construct($scope, $templateTypeStrategy, $templateTypeVariance, $name, $bound, $default); every argument borrowed ($defaultType NULL or IS_NULL for null); false = pending exception */ + [[nodiscard]] bool construct(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) const + { + /* parent::__construct($bound->getValue()) */ + double value; + if (UNEXPECTED(!pt_constant_float_get_value(Z_OBJ_P(bound), value))) return false; + zval arg; + ZVAL_DOUBLE(&arg, value); + if (UNEXPECTED(!pt_template_type_parent_construct(self, pt_ce_template_constant_float_type, 1, &arg))) return false; + pt_template_type_init(self, pt_ce_template_constant_float_type, scope, strategy, variance, name, bound, defaultType); + return true; + } + + /* new self(...) — exactly the class, as the twin's sites spell it; the + * bound checked as the twin's typed parameter checks it; UNDEF = + * pending exception */ + static zv::Val create(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) + { + return pt_template_type_create(pt_ce_template_constant_float_type, scope, strategy, variance, name, bound, defaultType); + } + +private: + zend_object *self; +}; + +} // namespace phpstanturbo + +using phpstanturbo::TemplateConstantFloatType; + +bool pt_template_constant_float_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) +{ + return pt_val_into(TemplateConstantFloatType::create(scope, strategy, variance, name, bound, defaultType), out); +} + +/* {{{ engine ABI glue: parameter parsing + registration */ + +#define PT_THIS TemplateConstantFloatType(Z_OBJ_P(ZEND_THIS)) + +PT_MINIT_REGISTRATION(pt_register_template_constant_float_type) +{ + reg::Class cls("PHPStan\\Type\\Generic\\TemplateConstantFloatType"); + ptdecl::TemplateConstantFloatType::declareClass(cls); + ptdecl::TemplateConstantFloatType::declareProperties(cls); + + cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) { + pt_template_ctor_args args; + PT_TEMPLATE_TYPE_PARSE_CTOR(args); + if (UNEXPECTED(!PT_THIS.construct(args.scope, args.strategy, args.variance, args.name, args.bound, args.defaultType))) RETURN_THROWS(); + }); + + /* the traits the twin uses, after the class's own methods */ + ptdecl::TemplateConstantFloatType::registerTraits(cls); + + cls.shadow(&pt_ce_template_constant_float_type); +} + +/* }}} */ diff --git a/turbo-ext/src/TemplateFloatRangeType.cpp b/turbo-ext/src/TemplateFloatRangeType.cpp new file mode 100644 index 00000000000..aa9fc4a889b --- /dev/null +++ b/turbo-ext/src/TemplateFloatRangeType.cpp @@ -0,0 +1,93 @@ +/* + * PHPStanTurbo\TemplateFloatRangeType — native implementation of + * PHPStan\Type\Generic\TemplateFloatRangeType. + * + * Declared as PHPStan\Type\Generic\TemplateFloatRangeType itself at + * activation: final, extending the native FloatRangeType and implementing + * the PHP TemplateType interface. The twin composes TemplateTypeTrait — the + * shared registrar in TypeTraits.cpp supplies its methods and the trait's six + * slots (after the parent's); the constructor runs + * parent::__construct($bound->getMin(), $bound->getMax()) and then the + * trait's slot writes. The comparisons are FloatRangeType's own: a T holds + * only values of its range, so what holds for every value of the range holds + * for the T. + */ + +#include "TypeTraits.h" +#include "generated/TemplateFloatRangeType.h" + +namespace sigs = ptdecl::TemplateFloatRangeType::sig; + +zend_class_entry *pt_ce_template_float_range_type = nullptr; + +namespace phpstanturbo { + +/* Mirrors PHPStan\Type\Generic\TemplateFloatRangeType. State lives in the + * parent's slots and the trait's six. */ +class TemplateFloatRangeType +{ +public: + explicit TemplateFloatRangeType(zend_object *self) : self(self) {} + + /* __construct($scope, $templateTypeStrategy, $templateTypeVariance, $name, $bound, $default); every argument borrowed ($defaultType NULL or IS_NULL for null); false = pending exception */ + [[nodiscard]] bool construct(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) const + { + /* parent::__construct($bound->getMin(), $bound->getMax()) */ + double min = 0.0, max = 0.0; + if (UNEXPECTED(!pt_float_range_bounds(Z_OBJ_P(bound), min, max))) return false; + zval args[2]; + ZVAL_DOUBLE(&args[0], min); + ZVAL_DOUBLE(&args[1], max); + if (UNEXPECTED(!pt_template_type_parent_construct(self, pt_ce_template_float_range_type, 2, args))) return false; + pt_template_type_init(self, pt_ce_template_float_range_type, scope, strategy, variance, name, bound, defaultType); + return true; + } + + /* new self(...) — exactly the class, as the twin's sites spell it; the + * bound checked as the twin's typed parameter checks it; UNDEF = + * pending exception */ + static zv::Val create(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) + { + return pt_template_type_create(pt_ce_template_float_range_type, scope, strategy, variance, name, bound, defaultType); + } + +private: + zend_object *self; +}; + +} // namespace phpstanturbo + +using phpstanturbo::TemplateFloatRangeType; + +bool pt_template_float_range_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) +{ + return pt_val_into(TemplateFloatRangeType::create(scope, strategy, variance, name, bound, defaultType), out); +} + +/* {{{ engine ABI glue: parameter parsing + registration */ + +#define PT_THIS TemplateFloatRangeType(Z_OBJ_P(ZEND_THIS)) + +PT_MINIT_REGISTRATION(pt_register_template_float_range_type) +{ + reg::Class cls("PHPStan\\Type\\Generic\\TemplateFloatRangeType"); + ptdecl::TemplateFloatRangeType::declareClass(cls); + ptdecl::TemplateFloatRangeType::declareProperties(cls); + + cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) { + pt_template_ctor_args args; + PT_TEMPLATE_TYPE_PARSE_CTOR(args); + if (UNEXPECTED(!PT_THIS.construct(args.scope, args.strategy, args.variance, args.name, args.bound, args.defaultType))) RETURN_THROWS(); + }); + + /* mirrors tryUnion() and tryIntersect(): a T merged with another range would no longer be a T */ + cls.method(sigs::tryUnion, pt_type_try_null_handler); + cls.method(sigs::tryIntersect, pt_type_try_null_handler); + + /* the traits the twin uses, after the class's own methods */ + ptdecl::TemplateFloatRangeType::registerTraits(cls); + + cls.shadow(&pt_ce_template_float_range_type); +} + +/* }}} */ diff --git a/turbo-ext/src/TemplateIntegerRangeType.cpp b/turbo-ext/src/TemplateIntegerRangeType.cpp new file mode 100644 index 00000000000..1c7ad25acb2 --- /dev/null +++ b/turbo-ext/src/TemplateIntegerRangeType.cpp @@ -0,0 +1,101 @@ +/* + * PHPStanTurbo\TemplateIntegerRangeType — native implementation of + * PHPStan\Type\Generic\TemplateIntegerRangeType. + * + * Declared as PHPStan\Type\Generic\TemplateIntegerRangeType itself at + * activation: final, extending the native IntegerRangeType and implementing + * the PHP TemplateType interface. The twin composes TemplateTypeTrait — the + * shared registrar in TypeTraits.cpp supplies its methods and the trait's six + * slots (after the parent's); the constructor runs + * parent::__construct($bound->getMin(), $bound->getMax()) and then the + * trait's slot writes. The comparisons are IntegerRangeType's own: a T holds + * only values of its range, so what holds for every value of the range holds + * for the T. + */ + +#include "TypeTraits.h" +#include "generated/TemplateIntegerRangeType.h" + +namespace sigs = ptdecl::TemplateIntegerRangeType::sig; + +zend_class_entry *pt_ce_template_integer_range_type = nullptr; + +namespace phpstanturbo { + +/* Mirrors PHPStan\Type\Generic\TemplateIntegerRangeType. State lives in the + * parent's slots and the trait's six. */ +class TemplateIntegerRangeType +{ +public: + explicit TemplateIntegerRangeType(zend_object *self) : self(self) {} + + /* __construct($scope, $templateTypeStrategy, $templateTypeVariance, $name, $bound, $default); every argument borrowed ($defaultType NULL or IS_NULL for null); false = pending exception */ + [[nodiscard]] bool construct(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) const + { + /* parent::__construct($bound->getMin(), $bound->getMax()) */ + NullableLong min = NullableLong::null(), max = NullableLong::null(); + if (UNEXPECTED(!pt_integer_range_bounds(Z_OBJ_P(bound), min, max))) return false; + zval args[2]; + if (min.isNull) { + ZVAL_NULL(&args[0]); + } else { + ZVAL_LONG(&args[0], min.value); + } + if (max.isNull) { + ZVAL_NULL(&args[1]); + } else { + ZVAL_LONG(&args[1], max.value); + } + if (UNEXPECTED(!pt_template_type_parent_construct(self, pt_ce_template_integer_range_type, 2, args))) return false; + pt_template_type_init(self, pt_ce_template_integer_range_type, scope, strategy, variance, name, bound, defaultType); + return true; + } + + /* new self(...) — exactly the class, as the twin's sites spell it; the + * bound checked as the twin's typed parameter checks it; UNDEF = + * pending exception */ + static zv::Val create(zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) + { + return pt_template_type_create(pt_ce_template_integer_range_type, scope, strategy, variance, name, bound, defaultType); + } + +private: + zend_object *self; +}; + +} // namespace phpstanturbo + +using phpstanturbo::TemplateIntegerRangeType; + +bool pt_template_integer_range_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType) +{ + return pt_val_into(TemplateIntegerRangeType::create(scope, strategy, variance, name, bound, defaultType), out); +} + +/* {{{ engine ABI glue: parameter parsing + registration */ + +#define PT_THIS TemplateIntegerRangeType(Z_OBJ_P(ZEND_THIS)) + +PT_MINIT_REGISTRATION(pt_register_template_integer_range_type) +{ + reg::Class cls("PHPStan\\Type\\Generic\\TemplateIntegerRangeType"); + ptdecl::TemplateIntegerRangeType::declareClass(cls); + ptdecl::TemplateIntegerRangeType::declareProperties(cls); + + cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) { + pt_template_ctor_args args; + PT_TEMPLATE_TYPE_PARSE_CTOR(args); + if (UNEXPECTED(!PT_THIS.construct(args.scope, args.strategy, args.variance, args.name, args.bound, args.defaultType))) RETURN_THROWS(); + }); + + /* mirrors tryUnion() and tryIntersect(): a T merged with another range would no longer be a T */ + cls.method(sigs::tryUnion, pt_type_try_null_handler); + cls.method(sigs::tryIntersect, pt_type_try_null_handler); + + /* the traits the twin uses, after the class's own methods */ + ptdecl::TemplateIntegerRangeType::registerTraits(cls); + + cls.shadow(&pt_ce_template_integer_range_type); +} + +/* }}} */ diff --git a/turbo-ext/src/TemplateTypeFactory.cpp b/turbo-ext/src/TemplateTypeFactory.cpp index 8fa4d8ae75f..b973dc87f35 100644 --- a/turbo-ext/src/TemplateTypeFactory.cpp +++ b/turbo-ext/src/TemplateTypeFactory.cpp @@ -94,7 +94,11 @@ class TemplateTypeFactory return of(pt_template_constant_string_type_new, scope, strategy, variance, nameStr, bound, defaultType); } - if (instanceof_function(boundClass, pt_ce_integer_type) && (boundClass == pt_ce_integer_type || instanceof_function(boundClass, pt_ce_integer_range_type) || isTemplate)) { + if (instanceof_function(boundClass, pt_ce_integer_range_type) && (boundClass == pt_ce_integer_range_type || isTemplate)) { + return of(pt_template_integer_range_type_new, scope, strategy, variance, nameStr, bound, defaultType); + } + + if (instanceof_function(boundClass, pt_ce_integer_type) && (boundClass == pt_ce_integer_type || isTemplate)) { return of(pt_template_integer_type_new, scope, strategy, variance, nameStr, bound, defaultType); } @@ -102,8 +106,15 @@ class TemplateTypeFactory return of(pt_template_constant_integer_type_new, scope, strategy, variance, nameStr, bound, defaultType); } - /* Catches plain FloatType and the float subtypes that narrowing a bound produces, a FloatRangeType or a ConstantFloatType, neither of which has a dedicated Template* class to fall into — like the twin */ - if (instanceof_function(boundClass, pt_ce_float_type)) { + if (instanceof_function(boundClass, pt_ce_float_range_type) && (boundClass == pt_ce_float_range_type || isTemplate)) { + return of(pt_template_float_range_type_new, scope, strategy, variance, nameStr, bound, defaultType); + } + + if (instanceof_function(boundClass, pt_ce_constant_float_type) && (boundClass == pt_ce_constant_float_type || isTemplate)) { + return of(pt_template_constant_float_type_new, scope, strategy, variance, nameStr, bound, defaultType); + } + + if (instanceof_function(boundClass, pt_ce_float_type) && (boundClass == pt_ce_float_type || isTemplate)) { return of(pt_template_float_type_new, scope, strategy, variance, nameStr, bound, defaultType); } diff --git a/turbo-ext/src/UnionType.cpp b/turbo-ext/src/UnionType.cpp index 3f72c25de6d..a995530d634 100644 --- a/turbo-ext/src/UnionType.cpp +++ b/turbo-ext/src/UnionType.cpp @@ -816,7 +816,8 @@ class UnionType } } if (!delegate) { - delegate = instanceof_function(Z_OBJCE_P(otherType), pt_ce_never_type) || instanceof_function(Z_OBJCE_P(otherType), pt_ce_integer_range_type) + delegate = instanceof_function(Z_OBJCE_P(otherType), pt_ce_never_type) + || (instanceof_function(Z_OBJCE_P(otherType), pt_ce_integer_range_type) && !instanceof_function(Z_OBJCE_P(otherType), pt_ce_template_integer_range_type)) // stands for its delegate, which can itself be a union || instanceof_function(Z_OBJCE_P(otherType), pt_ce_unresolved_template_argument_type); } diff --git a/turbo-ext/src/generated/FloatRangeType.h b/turbo-ext/src/generated/FloatRangeType.h index 8a78f75eff7..928cab11c4a 100644 --- a/turbo-ext/src/generated/FloatRangeType.h +++ b/turbo-ext/src/generated/FloatRangeType.h @@ -177,7 +177,7 @@ using Sig = reg::Sig; /* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ namespace sig { -inline constexpr sigtab::Sig __construct = { { 8 /* __construct */, 2, 0, 2, reg::NoArg, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig __construct = { { 8 /* __construct */, 2, 0, 2, reg::NoArg, ZEND_ACC_PROTECTED } }; inline constexpr sigtab::Sig fromInterval = { { 39 /* fromInterval */, 2, 2, 2, 4, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; inline constexpr sigtab::Sig toOrdinal = { { 58 /* toOrdinal */, 1, 5, 1, 6, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; inline constexpr sigtab::Sig fromOrdinal = { { 76 /* fromOrdinal */, 1, 7, 1, 8, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; diff --git a/turbo-ext/src/generated/IntegerRangeType.h b/turbo-ext/src/generated/IntegerRangeType.h index f04c634731e..fa9af519094 100644 --- a/turbo-ext/src/generated/IntegerRangeType.h +++ b/turbo-ext/src/generated/IntegerRangeType.h @@ -202,7 +202,7 @@ using Sig = reg::Sig; /* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ namespace sig { -inline constexpr sigtab::Sig __construct = { { 8 /* __construct */, 2, 0, 2, reg::NoArg, ZEND_ACC_PRIVATE } }; +inline constexpr sigtab::Sig __construct = { { 8 /* __construct */, 2, 0, 2, reg::NoArg, ZEND_ACC_PROTECTED } }; inline constexpr sigtab::Sig fromInterval = { { 47 /* fromInterval */, 2, 2, 3, 5, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; inline constexpr sigtab::Sig isDisjoint = { { 104 /* isDisjoint */, 4, 6, 5, 11, ZEND_ACC_PROTECTED | ZEND_ACC_STATIC } }; inline constexpr sigtab::Sig createAllSmallerThan = { { 121 /* createAllSmallerThan */, 1, 12, 1, 13, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC } }; diff --git a/turbo-ext/src/generated/TemplateConstantFloatType.h b/turbo-ext/src/generated/TemplateConstantFloatType.h new file mode 100644 index 00000000000..90b82d3b0a3 --- /dev/null +++ b/turbo-ext/src/generated/TemplateConstantFloatType.h @@ -0,0 +1,75 @@ +/* Generated by turbo-ext/bin/generate-declarations.php from + * src/Type/Generic/TemplateConstantFloatType.php — do not edit. */ + +#ifndef PHPSTANTURBO_GENERATED_TEMPLATE_CONSTANT_FLOAT_TYPE_H +#define PHPSTANTURBO_GENERATED_TEMPLATE_CONSTANT_FLOAT_TYPE_H + +#include "../reg.h" + +namespace ptdecl::TemplateConstantFloatType { + +/* the OBJ_PROP_NUM slots of the instance properties the class declares (the inherited ones come first) */ +namespace slot { +inline constexpr uint32_t name = 1; +inline constexpr uint32_t scope = 2; +inline constexpr uint32_t strategy = 3; +inline constexpr uint32_t variance = 4; +inline constexpr uint32_t bound = 5; +inline constexpr uint32_t default_ = 6; +} // namespace slot + +inline void declareClass(reg::Class &cls) +{ + cls.final(); + cls.parent("PHPStan\\Type\\Constant\\ConstantFloatType"); + cls.implements({ "PHPStan\\Type\\Generic\\TemplateType" }); +} + +/* the properties the class declares itself, in declaration order (a used trait's come from its registrar) */ +inline void declareProperties(reg::Class &cls) +{ + (void) cls; +} + +/* the shared registrars of the traits the twin uses, in its own order (a used trait's own traits after it) */ +inline void registerTraits(reg::Class &cls) +{ + pt_type_trait_template_type(cls); + pt_type_trait_undecided_comparison_compound(cls); + pt_type_trait_undecided_comparison(cls); +} + +/* the string and parameter tables the signatures below index into (see reg::Sig) */ +namespace sigtab { +inline constexpr char strings[] = + "scope\0" /* 0 */ + "PHPStan\\Type\\Generic\\TemplateTypeScope\0" /* 6 */ + "templateTypeStrategy\0" /* 45 */ + "PHPStan\\Type\\Generic\\TemplateTypeStrategy\0" /* 66 */ + "templateTypeVariance\0" /* 108 */ + "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 129 */ + "name\0" /* 171 */ + "bound\0" /* 176 */ + "PHPStan\\Type\\Constant\\ConstantFloatType\0" /* 182 */ + "default\0" /* 222 */ + "PHPStan\\Type\\Type\0" /* 230 */ + "__construct"; /* 248 */ +inline constexpr reg::PackedArg args[] = { + reg::packed(0, 0, 6), /* __construct $scope */ + reg::packed(45, 0, 66), /* __construct $templateTypeStrategy */ + reg::packed(108, 0, 129), /* __construct $templateTypeVariance */ + reg::packed(171, MAY_BE_STRING), /* __construct $name */ + reg::packed(176, 0, 182), /* __construct $bound */ + reg::packed(222, MAY_BE_NULL, 230), /* __construct $default */ +}; +using Sig = reg::Sig; +} // namespace sigtab + +/* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ +namespace sig { +inline constexpr sigtab::Sig __construct = { { 248 /* __construct */, 6, 0, 6, reg::NoArg, ZEND_ACC_PUBLIC } }; +} // namespace sig + +} // namespace ptdecl::TemplateConstantFloatType + +#endif diff --git a/turbo-ext/src/generated/TemplateFloatRangeType.h b/turbo-ext/src/generated/TemplateFloatRangeType.h new file mode 100644 index 00000000000..e3be039393c --- /dev/null +++ b/turbo-ext/src/generated/TemplateFloatRangeType.h @@ -0,0 +1,83 @@ +/* Generated by turbo-ext/bin/generate-declarations.php from + * src/Type/Generic/TemplateFloatRangeType.php — do not edit. */ + +#ifndef PHPSTANTURBO_GENERATED_TEMPLATE_FLOAT_RANGE_TYPE_H +#define PHPSTANTURBO_GENERATED_TEMPLATE_FLOAT_RANGE_TYPE_H + +#include "../reg.h" + +namespace ptdecl::TemplateFloatRangeType { + +/* the OBJ_PROP_NUM slots of the instance properties the class declares (the inherited ones come first) */ +namespace slot { +inline constexpr uint32_t name = 2; +inline constexpr uint32_t scope = 3; +inline constexpr uint32_t strategy = 4; +inline constexpr uint32_t variance = 5; +inline constexpr uint32_t bound = 6; +inline constexpr uint32_t default_ = 7; +} // namespace slot + +inline void declareClass(reg::Class &cls) +{ + cls.final(); + cls.parent("PHPStan\\Type\\FloatRangeType"); + cls.implements({ "PHPStan\\Type\\Generic\\TemplateType" }); +} + +/* the properties the class declares itself, in declaration order (a used trait's come from its registrar) */ +inline void declareProperties(reg::Class &cls) +{ + (void) cls; +} + +/* the shared registrars of the traits the twin uses, in its own order (a used trait's own traits after it) */ +inline void registerTraits(reg::Class &cls) +{ + pt_type_trait_template_type(cls); +} + +/* the string and parameter tables the signatures below index into (see reg::Sig) */ +namespace sigtab { +inline constexpr char strings[] = + "scope\0" /* 0 */ + "PHPStan\\Type\\Generic\\TemplateTypeScope\0" /* 6 */ + "templateTypeStrategy\0" /* 45 */ + "PHPStan\\Type\\Generic\\TemplateTypeStrategy\0" /* 66 */ + "templateTypeVariance\0" /* 108 */ + "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 129 */ + "name\0" /* 171 */ + "bound\0" /* 176 */ + "PHPStan\\Type\\FloatRangeType\0" /* 182 */ + "default\0" /* 210 */ + "PHPStan\\Type\\Type\0" /* 218 */ + "__construct\0" /* 236 */ + "otherType\0" /* 248 */ + "\0" /* 258 */ + "tryUnion\0" /* 259 */ + "tryIntersect"; /* 268 */ +inline constexpr reg::PackedArg args[] = { + reg::packed(0, 0, 6), /* __construct $scope */ + reg::packed(45, 0, 66), /* __construct $templateTypeStrategy */ + reg::packed(108, 0, 129), /* __construct $templateTypeVariance */ + reg::packed(171, MAY_BE_STRING), /* __construct $name */ + reg::packed(176, 0, 182), /* __construct $bound */ + reg::packed(210, MAY_BE_NULL, 218), /* __construct $default */ + reg::packed(248, 0, 218), /* tryUnion $otherType */ + reg::packed(258, MAY_BE_NULL, 218), /* tryUnion return */ + reg::packed(248, 0, 218), /* tryIntersect $otherType */ + reg::packed(258, MAY_BE_NULL, 218), /* tryIntersect return */ +}; +using Sig = reg::Sig; +} // namespace sigtab + +/* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ +namespace sig { +inline constexpr sigtab::Sig __construct = { { 236 /* __construct */, 6, 0, 6, reg::NoArg, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig tryUnion = { { 259 /* tryUnion */, 1, 6, 1, 7, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig tryIntersect = { { 268 /* tryIntersect */, 1, 8, 1, 9, ZEND_ACC_PUBLIC } }; +} // namespace sig + +} // namespace ptdecl::TemplateFloatRangeType + +#endif diff --git a/turbo-ext/src/generated/TemplateIntegerRangeType.h b/turbo-ext/src/generated/TemplateIntegerRangeType.h new file mode 100644 index 00000000000..d3726eb3bed --- /dev/null +++ b/turbo-ext/src/generated/TemplateIntegerRangeType.h @@ -0,0 +1,83 @@ +/* Generated by turbo-ext/bin/generate-declarations.php from + * src/Type/Generic/TemplateIntegerRangeType.php — do not edit. */ + +#ifndef PHPSTANTURBO_GENERATED_TEMPLATE_INTEGER_RANGE_TYPE_H +#define PHPSTANTURBO_GENERATED_TEMPLATE_INTEGER_RANGE_TYPE_H + +#include "../reg.h" + +namespace ptdecl::TemplateIntegerRangeType { + +/* the OBJ_PROP_NUM slots of the instance properties the class declares (the inherited ones come first) */ +namespace slot { +inline constexpr uint32_t name = 2; +inline constexpr uint32_t scope = 3; +inline constexpr uint32_t strategy = 4; +inline constexpr uint32_t variance = 5; +inline constexpr uint32_t bound = 6; +inline constexpr uint32_t default_ = 7; +} // namespace slot + +inline void declareClass(reg::Class &cls) +{ + cls.final(); + cls.parent("PHPStan\\Type\\IntegerRangeType"); + cls.implements({ "PHPStan\\Type\\Generic\\TemplateType" }); +} + +/* the properties the class declares itself, in declaration order (a used trait's come from its registrar) */ +inline void declareProperties(reg::Class &cls) +{ + (void) cls; +} + +/* the shared registrars of the traits the twin uses, in its own order (a used trait's own traits after it) */ +inline void registerTraits(reg::Class &cls) +{ + pt_type_trait_template_type(cls); +} + +/* the string and parameter tables the signatures below index into (see reg::Sig) */ +namespace sigtab { +inline constexpr char strings[] = + "scope\0" /* 0 */ + "PHPStan\\Type\\Generic\\TemplateTypeScope\0" /* 6 */ + "templateTypeStrategy\0" /* 45 */ + "PHPStan\\Type\\Generic\\TemplateTypeStrategy\0" /* 66 */ + "templateTypeVariance\0" /* 108 */ + "PHPStan\\Type\\Generic\\TemplateTypeVariance\0" /* 129 */ + "name\0" /* 171 */ + "bound\0" /* 176 */ + "PHPStan\\Type\\IntegerRangeType\0" /* 182 */ + "default\0" /* 212 */ + "PHPStan\\Type\\Type\0" /* 220 */ + "__construct\0" /* 238 */ + "otherType\0" /* 250 */ + "\0" /* 260 */ + "tryUnion\0" /* 261 */ + "tryIntersect"; /* 270 */ +inline constexpr reg::PackedArg args[] = { + reg::packed(0, 0, 6), /* __construct $scope */ + reg::packed(45, 0, 66), /* __construct $templateTypeStrategy */ + reg::packed(108, 0, 129), /* __construct $templateTypeVariance */ + reg::packed(171, MAY_BE_STRING), /* __construct $name */ + reg::packed(176, 0, 182), /* __construct $bound */ + reg::packed(212, MAY_BE_NULL, 220), /* __construct $default */ + reg::packed(250, 0, 220), /* tryUnion $otherType */ + reg::packed(260, MAY_BE_NULL, 220), /* tryUnion return */ + reg::packed(250, 0, 220), /* tryIntersect $otherType */ + reg::packed(260, MAY_BE_NULL, 220), /* tryIntersect return */ +}; +using Sig = reg::Sig; +} // namespace sigtab + +/* the signatures of the methods the class declares itself (a used trait's are in the trait's header) */ +namespace sig { +inline constexpr sigtab::Sig __construct = { { 238 /* __construct */, 6, 0, 6, reg::NoArg, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig tryUnion = { { 261 /* tryUnion */, 1, 6, 1, 7, ZEND_ACC_PUBLIC } }; +inline constexpr sigtab::Sig tryIntersect = { { 270 /* tryIntersect */, 1, 8, 1, 9, ZEND_ACC_PUBLIC } }; +} // namespace sig + +} // namespace ptdecl::TemplateIntegerRangeType + +#endif diff --git a/turbo-ext/src/support.h b/turbo-ext/src/support.h index b1fe9f50290..3fa62464769 100644 --- a/turbo-ext/src/support.h +++ b/turbo-ext/src/support.h @@ -1405,10 +1405,13 @@ extern zend_class_entry *pt_ce_template_array_type; extern zend_class_entry *pt_ce_template_benevolent_union_type; extern zend_class_entry *pt_ce_template_boolean_type; extern zend_class_entry *pt_ce_template_constant_array_type; +extern zend_class_entry *pt_ce_template_constant_float_type; extern zend_class_entry *pt_ce_template_constant_integer_type; extern zend_class_entry *pt_ce_template_constant_string_type; +extern zend_class_entry *pt_ce_template_float_range_type; extern zend_class_entry *pt_ce_template_float_type; extern zend_class_entry *pt_ce_template_generic_object_type; +extern zend_class_entry *pt_ce_template_integer_range_type; extern zend_class_entry *pt_ce_template_integer_type; extern zend_class_entry *pt_ce_template_intersection_type; extern zend_class_entry *pt_ce_template_iterable_type; @@ -1431,10 +1434,13 @@ bool pt_template_array_type_new(zval *out, zval *scope, zval *strategy, zval *va bool pt_template_benevolent_union_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_boolean_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_constant_array_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); +bool pt_template_constant_float_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_constant_integer_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_constant_string_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); +bool pt_template_float_range_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_float_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_generic_object_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); +bool pt_template_integer_range_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_integer_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_intersection_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); bool pt_template_iterable_type_new(zval *out, zval *scope, zval *strategy, zval *variance, zend_string *name, zval *bound, zval *defaultType); diff --git a/turbo-ext/tests/smoke.php b/turbo-ext/tests/smoke.php index c62e0783d50..1f76020192c 100644 --- a/turbo-ext/tests/smoke.php +++ b/turbo-ext/tests/smoke.php @@ -1193,7 +1193,7 @@ function observeTypeFamily(string $mode): array $typeFamilyPhp = observeTypeFamily('php'); $typeFamilyNative = observeTypeFamily('native'); -foreach ([\PHPStan\Type\BooleanType::class, \PHPStan\Type\Constant\ConstantBooleanType::class, \PHPStan\Type\IntegerType::class, \PHPStan\Type\Constant\ConstantIntegerType::class, \PHPStan\Type\IntegerRangeType::class, \PHPStan\Type\StringType::class, \PHPStan\Type\Constant\ConstantStringType::class, \PHPStan\Type\ClassStringType::class, \PHPStan\Type\Generic\GenericClassStringType::class, \PHPStan\Type\FloatType::class, \PHPStan\Type\Constant\ConstantFloatType::class, \PHPStan\Type\FloatRangeType::class, \PHPStan\Type\NullType::class, \PHPStan\Type\VoidType::class, \PHPStan\Type\NeverType::class, \PHPStan\Type\MixedType::class, \PHPStan\Type\StrictMixedType::class, \PHPStan\Type\ObjectWithoutClassType::class, \PHPStan\Type\StaticType::class, \PHPStan\Type\ThisType::class, \PHPStan\Type\Generic\GenericStaticType::class, \PHPStan\Type\ObjectShapeType::class, \PHPStan\Type\NonexistentParentClassType::class, \PHPStan\Type\ArrayType::class, \PHPStan\Type\Accessory\NonEmptyArrayType::class, \PHPStan\Type\Accessory\AccessoryArrayListType::class, \PHPStan\Type\Accessory\OversizedArrayType::class, \PHPStan\Type\Accessory\HasOffsetType::class, \PHPStan\Type\Accessory\HasOffsetValueType::class, \PHPStan\Type\Accessory\AccessoryNumericStringType::class, \PHPStan\Type\Accessory\AccessoryNonEmptyStringType::class, \PHPStan\Type\Accessory\AccessoryNonFalsyStringType::class, \PHPStan\Type\Accessory\AccessoryLiteralStringType::class, \PHPStan\Type\Accessory\AccessoryLowercaseStringType::class, \PHPStan\Type\Accessory\AccessoryUppercaseStringType::class, \PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType::class, \PHPStan\Type\Accessory\HasMethodType::class, \PHPStan\Type\Accessory\HasPropertyType::class, \PHPStan\Type\ObjectType::class, \PHPStan\Type\Generic\GenericObjectType::class, \PHPStan\Type\Enum\EnumCaseObjectType::class, \PHPStan\Type\IterableType::class, \PHPStan\Type\CallableType::class, \PHPStan\Type\ClosureType::class, \PHPStan\Type\Constant\ConstantArrayType::class, \PHPStan\Type\UnionType::class, \PHPStan\Type\BenevolentUnionType::class, \PHPStan\Type\IntersectionType::class, \PHPStan\Type\ErrorType::class, \PHPStan\Type\CircularTypeAliasErrorType::class, \PHPStan\Type\Generic\AbsorbedTemplateArgumentType::class, \PHPStan\Type\NonAcceptingNeverType::class, \PHPStan\Type\StringAlwaysAcceptingObjectWithToStringType::class, \PHPStan\Type\StringNeverAcceptingObjectWithToStringType::class, \PHPStan\Type\ResourceType::class, \PHPStan\Type\TypeUtils::class, \PHPStan\Type\TypehintHelper::class, \PHPStan\Type\Generic\TemplateTypeVariance::class, \PHPStan\Type\Generic\TemplateTypeVarianceMap::class, \PHPStan\Type\Generic\TemplateTypeMap::class, \PHPStan\Type\Generic\TemplateTypeScope::class, \PHPStan\Type\Generic\TemplateTypeReference::class, \PHPStan\Type\Generic\TemplateTypeHelper::class, \PHPStan\Type\Generic\ArrayKeyTemplateHelper::class, \PHPStan\Type\KeyOfType::class, \PHPStan\Type\ValueOfType::class, \PHPStan\Type\OffsetAccessType::class, \PHPStan\Type\ClassConstantAccessType::class, \PHPStan\Type\NewObjectType::class, \PHPStan\Type\ConditionalType::class, \PHPStan\Type\ConditionalTypeForParameter::class, \PHPStan\Type\LateResolvableArrayShapeType::class, \PHPStan\Type\Generic\UnresolvedTemplateArgumentType::class, \PHPStan\Type\Generic\TemplateArrayType::class, \PHPStan\Type\Generic\TemplateBenevolentUnionType::class, \PHPStan\Type\Generic\TemplateBooleanType::class, \PHPStan\Type\Generic\TemplateConstantArrayType::class, \PHPStan\Type\Generic\TemplateConstantIntegerType::class, \PHPStan\Type\Generic\TemplateConstantStringType::class, \PHPStan\Type\Generic\TemplateFloatType::class, \PHPStan\Type\Generic\TemplateGenericObjectType::class, \PHPStan\Type\Generic\TemplateIntegerType::class, \PHPStan\Type\Generic\TemplateIntersectionType::class, \PHPStan\Type\Generic\TemplateIterableType::class, \PHPStan\Type\Generic\TemplateMixedType::class, \PHPStan\Type\Generic\TemplateNullType::class, \PHPStan\Type\Generic\TemplateObjectShapeType::class, \PHPStan\Type\Generic\TemplateObjectType::class, \PHPStan\Type\Generic\TemplateObjectWithoutClassType::class, \PHPStan\Type\Generic\TemplateStrictMixedType::class, \PHPStan\Type\Generic\TemplateStringType::class, \PHPStan\Type\Generic\TemplateUnionType::class, \PHPStan\Type\Generic\TemplateTypeArgumentStrategy::class, \PHPStan\Type\Generic\TemplateTypeParameterStrategy::class, \PHPStan\Type\Generic\TemplateTypeFactory::class, \PHPStan\Type\Generic\TypeProjectionHelper::class, \PHPStan\Type\Constant\ConstantArrayTypeBuilder::class, \PHPStan\Type\UnionTypeHelper::class, \PHPStan\Type\CallableTypeHelper::class, \PHPStan\Type\Helper\GetTemplateTypeType::class, \PHPStan\Type\Generic\TemplateKeyOfType::class, \PHPStan\Rules\PhpDoc\UnresolvableTypeHelper::class, \PHPStan\Rules\RuleLevelHelper::class, \PHPStan\Reflection\Native\NativeParameterReflection::class, \PHPStan\Reflection\Type\CalledOnTypeUnresolvedMethodPrototypeReflection::class, \PHPStan\Reflection\Type\CalledOnTypeUnresolvedPropertyPrototypeReflection::class, \PHPStan\Reflection\Type\CallbackUnresolvedMethodPrototypeReflection::class, \PHPStan\Reflection\Type\CallbackUnresolvedPropertyPrototypeReflection::class, \PHPStan\Reflection\ResolvedMethodReflection::class, \PHPStan\Reflection\Dummy\ChangedTypeMethodReflection::class, \PHPStan\Reflection\Callables\SimpleImpurePoint::class, \PHPStan\Reflection\SideEffects::class, \PHPStan\Reflection\PassedByReference::class, \PHPStan\Reflection\Php\DummyParameter::class, \PHPStan\Reflection\Php\ExtendedDummyParameter::class, \PHPStan\Analyser\ArgumentsNormalizer::class, \PHPStan\Reflection\ParametersAcceptorSelector::class, \PHPStan\Reflection\Php\PhpParameterReflection::class, \PHPStan\Reflection\Native\ExtendedNativeParameterReflection::class, \PHPStan\Reflection\FunctionVariant::class, \PHPStan\Reflection\ExtendedFunctionVariant::class, \PHPStan\Reflection\ExtendedCallableFunctionVariant::class, \PHPStan\Reflection\ResolvedFunctionVariantWithOriginal::class, \PHPStan\Reflection\TrivialParametersAcceptor::class, \PHPStan\Reflection\Assertions::class, \PHPStan\Reflection\InitializerExprTypeResolver::class, \PHPStan\Type\ValueSet::class, \PHPStan\Analyser\Generics\TemplateArgumentConstraints::class, \PHPStan\Analyser\Generics\TemplateArgumentObserver::class, \PHPStan\Analyser\Generics\TemplateArgumentResolver::class, \PHPStan\Analyser\RicherScopeGetTypeHelper::class, \PHPStan\Analyser\NullsafeOperatorHelper::class, \PHPStan\Analyser\LoopWrittenVariableNames::class, \PHPStan\Reflection\Php\PhpPropertyReflection::class, \PHPStan\Reflection\Dummy\ChangedTypePropertyReflection::class, \PHPStan\Reflection\ResolvedPropertyReflection::class, \PHPStan\Type\StringSet::class] as $typeClass) { +foreach ([\PHPStan\Type\BooleanType::class, \PHPStan\Type\Constant\ConstantBooleanType::class, \PHPStan\Type\IntegerType::class, \PHPStan\Type\Constant\ConstantIntegerType::class, \PHPStan\Type\IntegerRangeType::class, \PHPStan\Type\StringType::class, \PHPStan\Type\Constant\ConstantStringType::class, \PHPStan\Type\ClassStringType::class, \PHPStan\Type\Generic\GenericClassStringType::class, \PHPStan\Type\FloatType::class, \PHPStan\Type\Constant\ConstantFloatType::class, \PHPStan\Type\FloatRangeType::class, \PHPStan\Type\NullType::class, \PHPStan\Type\VoidType::class, \PHPStan\Type\NeverType::class, \PHPStan\Type\MixedType::class, \PHPStan\Type\StrictMixedType::class, \PHPStan\Type\ObjectWithoutClassType::class, \PHPStan\Type\StaticType::class, \PHPStan\Type\ThisType::class, \PHPStan\Type\Generic\GenericStaticType::class, \PHPStan\Type\ObjectShapeType::class, \PHPStan\Type\NonexistentParentClassType::class, \PHPStan\Type\ArrayType::class, \PHPStan\Type\Accessory\NonEmptyArrayType::class, \PHPStan\Type\Accessory\AccessoryArrayListType::class, \PHPStan\Type\Accessory\OversizedArrayType::class, \PHPStan\Type\Accessory\HasOffsetType::class, \PHPStan\Type\Accessory\HasOffsetValueType::class, \PHPStan\Type\Accessory\AccessoryNumericStringType::class, \PHPStan\Type\Accessory\AccessoryNonEmptyStringType::class, \PHPStan\Type\Accessory\AccessoryNonFalsyStringType::class, \PHPStan\Type\Accessory\AccessoryLiteralStringType::class, \PHPStan\Type\Accessory\AccessoryLowercaseStringType::class, \PHPStan\Type\Accessory\AccessoryUppercaseStringType::class, \PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType::class, \PHPStan\Type\Accessory\HasMethodType::class, \PHPStan\Type\Accessory\HasPropertyType::class, \PHPStan\Type\ObjectType::class, \PHPStan\Type\Generic\GenericObjectType::class, \PHPStan\Type\Enum\EnumCaseObjectType::class, \PHPStan\Type\IterableType::class, \PHPStan\Type\CallableType::class, \PHPStan\Type\ClosureType::class, \PHPStan\Type\Constant\ConstantArrayType::class, \PHPStan\Type\UnionType::class, \PHPStan\Type\BenevolentUnionType::class, \PHPStan\Type\IntersectionType::class, \PHPStan\Type\ErrorType::class, \PHPStan\Type\CircularTypeAliasErrorType::class, \PHPStan\Type\Generic\AbsorbedTemplateArgumentType::class, \PHPStan\Type\NonAcceptingNeverType::class, \PHPStan\Type\StringAlwaysAcceptingObjectWithToStringType::class, \PHPStan\Type\StringNeverAcceptingObjectWithToStringType::class, \PHPStan\Type\ResourceType::class, \PHPStan\Type\TypeUtils::class, \PHPStan\Type\TypehintHelper::class, \PHPStan\Type\Generic\TemplateTypeVariance::class, \PHPStan\Type\Generic\TemplateTypeVarianceMap::class, \PHPStan\Type\Generic\TemplateTypeMap::class, \PHPStan\Type\Generic\TemplateTypeScope::class, \PHPStan\Type\Generic\TemplateTypeReference::class, \PHPStan\Type\Generic\TemplateTypeHelper::class, \PHPStan\Type\Generic\ArrayKeyTemplateHelper::class, \PHPStan\Type\KeyOfType::class, \PHPStan\Type\ValueOfType::class, \PHPStan\Type\OffsetAccessType::class, \PHPStan\Type\ClassConstantAccessType::class, \PHPStan\Type\NewObjectType::class, \PHPStan\Type\ConditionalType::class, \PHPStan\Type\ConditionalTypeForParameter::class, \PHPStan\Type\LateResolvableArrayShapeType::class, \PHPStan\Type\Generic\UnresolvedTemplateArgumentType::class, \PHPStan\Type\Generic\TemplateArrayType::class, \PHPStan\Type\Generic\TemplateBenevolentUnionType::class, \PHPStan\Type\Generic\TemplateBooleanType::class, \PHPStan\Type\Generic\TemplateConstantArrayType::class, \PHPStan\Type\Generic\TemplateConstantFloatType::class, \PHPStan\Type\Generic\TemplateConstantIntegerType::class, \PHPStan\Type\Generic\TemplateConstantStringType::class, \PHPStan\Type\Generic\TemplateFloatRangeType::class, \PHPStan\Type\Generic\TemplateFloatType::class, \PHPStan\Type\Generic\TemplateGenericObjectType::class, \PHPStan\Type\Generic\TemplateIntegerRangeType::class, \PHPStan\Type\Generic\TemplateIntegerType::class, \PHPStan\Type\Generic\TemplateIntersectionType::class, \PHPStan\Type\Generic\TemplateIterableType::class, \PHPStan\Type\Generic\TemplateMixedType::class, \PHPStan\Type\Generic\TemplateNullType::class, \PHPStan\Type\Generic\TemplateObjectShapeType::class, \PHPStan\Type\Generic\TemplateObjectType::class, \PHPStan\Type\Generic\TemplateObjectWithoutClassType::class, \PHPStan\Type\Generic\TemplateStrictMixedType::class, \PHPStan\Type\Generic\TemplateStringType::class, \PHPStan\Type\Generic\TemplateUnionType::class, \PHPStan\Type\Generic\TemplateTypeArgumentStrategy::class, \PHPStan\Type\Generic\TemplateTypeParameterStrategy::class, \PHPStan\Type\Generic\TemplateTypeFactory::class, \PHPStan\Type\Generic\TypeProjectionHelper::class, \PHPStan\Type\Constant\ConstantArrayTypeBuilder::class, \PHPStan\Type\UnionTypeHelper::class, \PHPStan\Type\CallableTypeHelper::class, \PHPStan\Type\Helper\GetTemplateTypeType::class, \PHPStan\Type\Generic\TemplateKeyOfType::class, \PHPStan\Rules\PhpDoc\UnresolvableTypeHelper::class, \PHPStan\Rules\RuleLevelHelper::class, \PHPStan\Reflection\Native\NativeParameterReflection::class, \PHPStan\Reflection\Type\CalledOnTypeUnresolvedMethodPrototypeReflection::class, \PHPStan\Reflection\Type\CalledOnTypeUnresolvedPropertyPrototypeReflection::class, \PHPStan\Reflection\Type\CallbackUnresolvedMethodPrototypeReflection::class, \PHPStan\Reflection\Type\CallbackUnresolvedPropertyPrototypeReflection::class, \PHPStan\Reflection\ResolvedMethodReflection::class, \PHPStan\Reflection\Dummy\ChangedTypeMethodReflection::class, \PHPStan\Reflection\Callables\SimpleImpurePoint::class, \PHPStan\Reflection\SideEffects::class, \PHPStan\Reflection\PassedByReference::class, \PHPStan\Reflection\Php\DummyParameter::class, \PHPStan\Reflection\Php\ExtendedDummyParameter::class, \PHPStan\Analyser\ArgumentsNormalizer::class, \PHPStan\Reflection\ParametersAcceptorSelector::class, \PHPStan\Reflection\Php\PhpParameterReflection::class, \PHPStan\Reflection\Native\ExtendedNativeParameterReflection::class, \PHPStan\Reflection\FunctionVariant::class, \PHPStan\Reflection\ExtendedFunctionVariant::class, \PHPStan\Reflection\ExtendedCallableFunctionVariant::class, \PHPStan\Reflection\ResolvedFunctionVariantWithOriginal::class, \PHPStan\Reflection\TrivialParametersAcceptor::class, \PHPStan\Reflection\Assertions::class, \PHPStan\Reflection\InitializerExprTypeResolver::class, \PHPStan\Type\ValueSet::class, \PHPStan\Analyser\Generics\TemplateArgumentConstraints::class, \PHPStan\Analyser\Generics\TemplateArgumentObserver::class, \PHPStan\Analyser\Generics\TemplateArgumentResolver::class, \PHPStan\Analyser\RicherScopeGetTypeHelper::class, \PHPStan\Analyser\NullsafeOperatorHelper::class, \PHPStan\Analyser\LoopWrittenVariableNames::class, \PHPStan\Reflection\Php\PhpPropertyReflection::class, \PHPStan\Reflection\Dummy\ChangedTypePropertyReflection::class, \PHPStan\Reflection\ResolvedPropertyReflection::class, \PHPStan\Type\StringSet::class] as $typeClass) { check(($typeFamilyPhp["native $typeClass"] ?? null) === false, "type-family.php php: $typeClass is the PHP twin"); check(($typeFamilyNative["native $typeClass"] ?? null) === true, "type-family.php native: $typeClass is the native class"); unset($typeFamilyPhp["native $typeClass"], $typeFamilyNative["native $typeClass"]); @@ -1929,10 +1929,13 @@ public function traverse(\PHPStan\Type\Type $type, callable $traverse): \PHPStan $covered[\PHPStan\Type\Generic\TemplateBenevolentUnionType::class] = true; $covered[\PHPStan\Type\Generic\TemplateBooleanType::class] = true; $covered[\PHPStan\Type\Generic\TemplateConstantArrayType::class] = true; +$covered[\PHPStan\Type\Generic\TemplateConstantFloatType::class] = true; $covered[\PHPStan\Type\Generic\TemplateConstantIntegerType::class] = true; $covered[\PHPStan\Type\Generic\TemplateConstantStringType::class] = true; +$covered[\PHPStan\Type\Generic\TemplateFloatRangeType::class] = true; $covered[\PHPStan\Type\Generic\TemplateFloatType::class] = true; $covered[\PHPStan\Type\Generic\TemplateGenericObjectType::class] = true; +$covered[\PHPStan\Type\Generic\TemplateIntegerRangeType::class] = true; $covered[\PHPStan\Type\Generic\TemplateIntegerType::class] = true; $covered[\PHPStan\Type\Generic\TemplateIntersectionType::class] = true; $covered[\PHPStan\Type\Generic\TemplateIterableType::class] = true; diff --git a/turbo-ext/tests/type-family.php b/turbo-ext/tests/type-family.php index d6fa4dd9734..fd7c4871cec 100644 --- a/turbo-ext/tests/type-family.php +++ b/turbo-ext/tests/type-family.php @@ -56,7 +56,7 @@ // which implementation answered: smoke.php holds the php run to false and // the native run to true, so the two sets can never be one implementation // compared against itself -foreach ([\PHPStan\Type\BooleanType::class, \PHPStan\Type\Constant\ConstantBooleanType::class, \PHPStan\Type\IntegerType::class, \PHPStan\Type\Constant\ConstantIntegerType::class, \PHPStan\Type\IntegerRangeType::class, \PHPStan\Type\StringType::class, \PHPStan\Type\Constant\ConstantStringType::class, \PHPStan\Type\ClassStringType::class, \PHPStan\Type\Generic\GenericClassStringType::class, \PHPStan\Type\FloatType::class, \PHPStan\Type\Constant\ConstantFloatType::class, \PHPStan\Type\FloatRangeType::class, \PHPStan\Type\NullType::class, \PHPStan\Type\VoidType::class, \PHPStan\Type\NeverType::class, \PHPStan\Type\MixedType::class, \PHPStan\Type\StrictMixedType::class, \PHPStan\Type\ObjectWithoutClassType::class, \PHPStan\Type\StaticType::class, \PHPStan\Type\ThisType::class, \PHPStan\Type\Generic\GenericStaticType::class, \PHPStan\Type\ObjectShapeType::class, \PHPStan\Type\NonexistentParentClassType::class, \PHPStan\Type\ArrayType::class, \PHPStan\Type\Accessory\NonEmptyArrayType::class, \PHPStan\Type\Accessory\AccessoryArrayListType::class, \PHPStan\Type\Accessory\OversizedArrayType::class, \PHPStan\Type\Accessory\HasOffsetType::class, \PHPStan\Type\Accessory\HasOffsetValueType::class, \PHPStan\Type\Accessory\AccessoryNumericStringType::class, \PHPStan\Type\Accessory\AccessoryNonEmptyStringType::class, \PHPStan\Type\Accessory\AccessoryNonFalsyStringType::class, \PHPStan\Type\Accessory\AccessoryLiteralStringType::class, \PHPStan\Type\Accessory\AccessoryLowercaseStringType::class, \PHPStan\Type\Accessory\AccessoryUppercaseStringType::class, \PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType::class, \PHPStan\Type\Accessory\HasMethodType::class, \PHPStan\Type\Accessory\HasPropertyType::class, \PHPStan\Type\ObjectType::class, \PHPStan\Type\Generic\GenericObjectType::class, \PHPStan\Type\Enum\EnumCaseObjectType::class, \PHPStan\Type\IterableType::class, \PHPStan\Type\CallableType::class, \PHPStan\Type\ClosureType::class, \PHPStan\Type\Constant\ConstantArrayType::class, \PHPStan\Type\UnionType::class, \PHPStan\Type\BenevolentUnionType::class, \PHPStan\Type\IntersectionType::class, \PHPStan\Type\ErrorType::class, \PHPStan\Type\CircularTypeAliasErrorType::class, \PHPStan\Type\Generic\AbsorbedTemplateArgumentType::class, \PHPStan\Type\NonAcceptingNeverType::class, \PHPStan\Type\StringAlwaysAcceptingObjectWithToStringType::class, \PHPStan\Type\StringNeverAcceptingObjectWithToStringType::class, \PHPStan\Type\ResourceType::class, \PHPStan\Type\KeyOfType::class, \PHPStan\Type\ValueOfType::class, \PHPStan\Type\OffsetAccessType::class, \PHPStan\Type\ClassConstantAccessType::class, \PHPStan\Type\NewObjectType::class, \PHPStan\Type\ConditionalType::class, \PHPStan\Type\ConditionalTypeForParameter::class, \PHPStan\Type\LateResolvableArrayShapeType::class, \PHPStan\Type\Generic\UnresolvedTemplateArgumentType::class, \PHPStan\Type\Generic\TemplateArrayType::class, \PHPStan\Type\Generic\TemplateBenevolentUnionType::class, \PHPStan\Type\Generic\TemplateBooleanType::class, \PHPStan\Type\Generic\TemplateConstantArrayType::class, \PHPStan\Type\Generic\TemplateConstantIntegerType::class, \PHPStan\Type\Generic\TemplateConstantStringType::class, \PHPStan\Type\Generic\TemplateFloatType::class, \PHPStan\Type\Generic\TemplateGenericObjectType::class, \PHPStan\Type\Generic\TemplateIntegerType::class, \PHPStan\Type\Generic\TemplateIntersectionType::class, \PHPStan\Type\Generic\TemplateIterableType::class, \PHPStan\Type\Generic\TemplateMixedType::class, \PHPStan\Type\Generic\TemplateNullType::class, \PHPStan\Type\Generic\TemplateObjectShapeType::class, \PHPStan\Type\Generic\TemplateObjectType::class, \PHPStan\Type\Generic\TemplateObjectWithoutClassType::class, \PHPStan\Type\Generic\TemplateStrictMixedType::class, \PHPStan\Type\Generic\TemplateStringType::class, \PHPStan\Type\Generic\TemplateUnionType::class, \PHPStan\Type\Generic\TemplateKeyOfType::class] as $typeClass) { +foreach ([\PHPStan\Type\BooleanType::class, \PHPStan\Type\Constant\ConstantBooleanType::class, \PHPStan\Type\IntegerType::class, \PHPStan\Type\Constant\ConstantIntegerType::class, \PHPStan\Type\IntegerRangeType::class, \PHPStan\Type\StringType::class, \PHPStan\Type\Constant\ConstantStringType::class, \PHPStan\Type\ClassStringType::class, \PHPStan\Type\Generic\GenericClassStringType::class, \PHPStan\Type\FloatType::class, \PHPStan\Type\Constant\ConstantFloatType::class, \PHPStan\Type\FloatRangeType::class, \PHPStan\Type\NullType::class, \PHPStan\Type\VoidType::class, \PHPStan\Type\NeverType::class, \PHPStan\Type\MixedType::class, \PHPStan\Type\StrictMixedType::class, \PHPStan\Type\ObjectWithoutClassType::class, \PHPStan\Type\StaticType::class, \PHPStan\Type\ThisType::class, \PHPStan\Type\Generic\GenericStaticType::class, \PHPStan\Type\ObjectShapeType::class, \PHPStan\Type\NonexistentParentClassType::class, \PHPStan\Type\ArrayType::class, \PHPStan\Type\Accessory\NonEmptyArrayType::class, \PHPStan\Type\Accessory\AccessoryArrayListType::class, \PHPStan\Type\Accessory\OversizedArrayType::class, \PHPStan\Type\Accessory\HasOffsetType::class, \PHPStan\Type\Accessory\HasOffsetValueType::class, \PHPStan\Type\Accessory\AccessoryNumericStringType::class, \PHPStan\Type\Accessory\AccessoryNonEmptyStringType::class, \PHPStan\Type\Accessory\AccessoryNonFalsyStringType::class, \PHPStan\Type\Accessory\AccessoryLiteralStringType::class, \PHPStan\Type\Accessory\AccessoryLowercaseStringType::class, \PHPStan\Type\Accessory\AccessoryUppercaseStringType::class, \PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType::class, \PHPStan\Type\Accessory\HasMethodType::class, \PHPStan\Type\Accessory\HasPropertyType::class, \PHPStan\Type\ObjectType::class, \PHPStan\Type\Generic\GenericObjectType::class, \PHPStan\Type\Enum\EnumCaseObjectType::class, \PHPStan\Type\IterableType::class, \PHPStan\Type\CallableType::class, \PHPStan\Type\ClosureType::class, \PHPStan\Type\Constant\ConstantArrayType::class, \PHPStan\Type\UnionType::class, \PHPStan\Type\BenevolentUnionType::class, \PHPStan\Type\IntersectionType::class, \PHPStan\Type\ErrorType::class, \PHPStan\Type\CircularTypeAliasErrorType::class, \PHPStan\Type\Generic\AbsorbedTemplateArgumentType::class, \PHPStan\Type\NonAcceptingNeverType::class, \PHPStan\Type\StringAlwaysAcceptingObjectWithToStringType::class, \PHPStan\Type\StringNeverAcceptingObjectWithToStringType::class, \PHPStan\Type\ResourceType::class, \PHPStan\Type\KeyOfType::class, \PHPStan\Type\ValueOfType::class, \PHPStan\Type\OffsetAccessType::class, \PHPStan\Type\ClassConstantAccessType::class, \PHPStan\Type\NewObjectType::class, \PHPStan\Type\ConditionalType::class, \PHPStan\Type\ConditionalTypeForParameter::class, \PHPStan\Type\LateResolvableArrayShapeType::class, \PHPStan\Type\Generic\UnresolvedTemplateArgumentType::class, \PHPStan\Type\Generic\TemplateArrayType::class, \PHPStan\Type\Generic\TemplateBenevolentUnionType::class, \PHPStan\Type\Generic\TemplateBooleanType::class, \PHPStan\Type\Generic\TemplateConstantArrayType::class, \PHPStan\Type\Generic\TemplateConstantFloatType::class, \PHPStan\Type\Generic\TemplateConstantIntegerType::class, \PHPStan\Type\Generic\TemplateConstantStringType::class, \PHPStan\Type\Generic\TemplateFloatRangeType::class, \PHPStan\Type\Generic\TemplateFloatType::class, \PHPStan\Type\Generic\TemplateGenericObjectType::class, \PHPStan\Type\Generic\TemplateIntegerRangeType::class, \PHPStan\Type\Generic\TemplateIntegerType::class, \PHPStan\Type\Generic\TemplateIntersectionType::class, \PHPStan\Type\Generic\TemplateIterableType::class, \PHPStan\Type\Generic\TemplateMixedType::class, \PHPStan\Type\Generic\TemplateNullType::class, \PHPStan\Type\Generic\TemplateObjectShapeType::class, \PHPStan\Type\Generic\TemplateObjectType::class, \PHPStan\Type\Generic\TemplateObjectWithoutClassType::class, \PHPStan\Type\Generic\TemplateStrictMixedType::class, \PHPStan\Type\Generic\TemplateStringType::class, \PHPStan\Type\Generic\TemplateUnionType::class, \PHPStan\Type\Generic\TemplateKeyOfType::class] as $typeClass) { $observations["native $typeClass"] = (new ReflectionMethod($typeClass, 'describe'))->isInternal(); } @@ -5552,7 +5552,7 @@ public function resolve(): \PHPStan\Type\Type } -// ---- TemplateArrayType / TemplateBenevolentUnionType / TemplateBooleanType / TemplateConstantArrayType / TemplateConstantIntegerType / TemplateConstantStringType / TemplateFloatType / TemplateGenericObjectType / TemplateIntegerType / TemplateIntersectionType / TemplateIterableType / TemplateMixedType / TemplateNullType / TemplateObjectShapeType / TemplateObjectType / TemplateObjectWithoutClassType / TemplateStrictMixedType / TemplateStringType / TemplateUnionType / TemplateTypeArgumentStrategy / TemplateTypeParameterStrategy / TemplateTypeFactory / TypeProjectionHelper ---- +// ---- TemplateArrayType / TemplateBenevolentUnionType / TemplateBooleanType / TemplateConstantArrayType / TemplateConstantFloatType / TemplateConstantIntegerType / TemplateConstantStringType / TemplateFloatRangeType / TemplateFloatType / TemplateGenericObjectType / TemplateIntegerRangeType / TemplateIntegerType / TemplateIntersectionType / TemplateIterableType / TemplateMixedType / TemplateNullType / TemplateObjectShapeType / TemplateObjectType / TemplateObjectWithoutClassType / TemplateStrictMixedType / TemplateStringType / TemplateUnionType / TemplateTypeArgumentStrategy / TemplateTypeParameterStrategy / TemplateTypeFactory / TypeProjectionHelper ---- // the template family: every Template*Type over its native parent (built // through TemplateTypeFactory::create() over the bounds it dispatches on), // the TemplateTypeTrait bodies (describe, the compound dispatch of @@ -5596,6 +5596,7 @@ public function resolve(): \PHPStan\Type\Type 'floatRange' => \PHPStan\Type\FloatRangeType::fromInterval(0.0, 10.0), 'floatRangeNegative' => \PHPStan\Type\FloatRangeType::fromInterval(-10.0, -1.0), 'floatMinus1_5' => new \PHPStan\Type\Constant\ConstantFloatType(-1.5), + 'float1_5' => new \PHPStan\Type\Constant\ConstantFloatType(1.5), 'nan' => new \PHPStan\Type\Constant\ConstantFloatType(NAN), 'bool' => new \PHPStan\Type\BooleanType(), 'true' => new \PHPStan\Type\Constant\ConstantBooleanType(true), @@ -5638,7 +5639,10 @@ public function resolve(): \PHPStan\Type\Type $templateOthers = static fn (): array => [ 'int' => new \PHPStan\Type\IntegerType(), 'int1' => new \PHPStan\Type\Constant\ConstantIntegerType(1), + 'range' => \PHPStan\Type\IntegerRangeType::fromInterval(3, 20), 'float' => new \PHPStan\Type\FloatType(), + 'floatRange' => \PHPStan\Type\FloatRangeType::fromInterval(0.5, 20.0), + 'float1_5' => new \PHPStan\Type\Constant\ConstantFloatType(1.5), 'bool' => new \PHPStan\Type\BooleanType(), 'string' => new \PHPStan\Type\StringType(), 'stringA' => new \PHPStan\Type\Constant\ConstantStringType('a'), @@ -5780,6 +5784,11 @@ public function resolve(): \PHPStan\Type\Type $r["$name union $otherName"] = $view(\PHPStan\Type\TypeCombinator::union($subject, $other)); $r["$name intersect $otherName"] = $view(\PHPStan\Type\TypeCombinator::intersect($subject, $other)); $r["$name remove $otherName"] = $view(\PHPStan\Type\TypeCombinator::remove($subject, $other)); + // the other side of the pair, which must not take a template for all of its bound + $r["$otherName tryRemove $name"] = $view($other->tryRemove($subject)); + $r["$otherName tryUnion $name"] = $view($other->tryUnion($subject)); + $r["$otherName tryIntersect $name"] = $view($other->tryIntersect($subject)); + $r["$otherName remove $name"] = $view(\PHPStan\Type\TypeCombinator::remove($other, $subject)); } foreach (['null parameter none', 'int parameter none', 'int argument int', 'union parameter none', 'subclass'] as $peerName) { $peer = $subjects[$peerName];