Repository navigation
Report array&callable pass as wrong param
#5573
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
Changes from 1 commit
d4dcc5c
7507cc4
20dccde
8bbf9bb
ca76429
3afa0ac
3b83616
9759075
507d88a
14d9af0
631138c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…lable and array&hasOffsetValue Tests cover both success and failure cases: - array&callable isAcceptedBy array/constantArray - array&hasOffsetValue isAcceptedBy array/constantArray - array&callable isSubTypeOf array - array&hasOffsetValue isSubTypeOf array The isSubTypeOf tests confirm that the issue does NOT exist there — isSubTypeOf correctly returns No for incompatible types (e.g. array&callable is not a subtype of array<int>, and array&hasOffsetValue(3,int) is not a subtype of array<string>). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,118 @@ public function testAccepts(Type $type, Type $otherType, TrinaryLogic $expectedR | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return Iterator<int, array{Type, Type, TrinaryLogic}> | ||
| */ | ||
| public static function dataIsAcceptedBy(): Iterator | ||
| { | ||
| // array&callable isAcceptedBy array - success | ||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
|
||
| // array&callable isAcceptedBy array - failure | ||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ArrayType(new MixedType(), new IntegerType()), | ||
| TrinaryLogic::createNo(), | ||
| ]; | ||
|
|
||
| // array&callable isAcceptedBy constantArray - success | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ConstantArrayType( | ||
| [new ConstantIntegerType(0), new ConstantIntegerType(1)], | ||
| [new UnionType([new ObjectType('stdClass'), new StringType()]), new StringType()], | ||
| ), | ||
| TrinaryLogic::createMaybe(), | ||
| ]; | ||
|
|
||
| // array&callable isAcceptedBy constantArray - failure | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ConstantArrayType( | ||
| [new ConstantIntegerType(0), new ConstantIntegerType(1)], | ||
| [new StringType(), new StringType()], | ||
| ), | ||
| TrinaryLogic::createMaybe(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isAcceptedBy array - success | ||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
Comment on lines
+151
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could have another test like "array&hasOffsetValue" is accepted by a union of e.g. "array|array"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the test case staabm requested: |
||
|
|
||
| // array&hasOffsetValue isAcceptedBy array - failure | ||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new StringType()), | ||
| TrinaryLogic::createNo(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isAcceptedBy array - success (matching value type) | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new IntegerType()), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isAcceptedBy constantArray - success | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(0), new IntegerType()), | ||
| ]), | ||
| new ConstantArrayType( | ||
| [new ConstantIntegerType(0), new ConstantIntegerType(1)], | ||
| [new IntegerType(), new IntegerType()], | ||
| ), | ||
| TrinaryLogic::createMaybe(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isAcceptedBy constantArray - failure | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
|
VincentLanglet marked this conversation as resolved.
Resolved
|
||
| ]), | ||
| new ConstantArrayType( | ||
| [new ConstantIntegerType(0), new ConstantIntegerType(1)], | ||
| [new StringType(), new StringType()], | ||
| ), | ||
| TrinaryLogic::createMaybe(), | ||
| ]; | ||
| } | ||
|
|
||
| #[DataProvider('dataIsAcceptedBy')] | ||
| public function testIsAcceptedBy(Type $type, Type $acceptingType, TrinaryLogic $expectedResult): void | ||
| { | ||
| $actualResult = $acceptingType->accepts($type, true)->result; | ||
| $this->assertSame( | ||
| $expectedResult->describe(), | ||
| $actualResult->describe(), | ||
| sprintf('%s -> isAcceptedBy(%s)', $type->describe(VerbosityLevel::precise()), $acceptingType->describe(VerbosityLevel::precise())), | ||
| ); | ||
| } | ||
|
|
||
| public static function dataIsCallable(): array | ||
| { | ||
| return [ | ||
|
|
@@ -362,6 +474,53 @@ public static function dataIsSubTypeOf(): Iterator | |
| ]), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
|
||
| // array&callable isSubTypeOf array - success | ||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
|
||
| // array&callable isSubTypeOf array<int> - failure | ||
| yield [ | ||
| new IntersectionType([new ArrayType(new MixedType(), new MixedType()), new CallableType()]), | ||
| new ArrayType(new MixedType(), new IntegerType()), | ||
| TrinaryLogic::createNo(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isSubTypeOf array - success | ||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| TrinaryLogic::createYes(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isSubTypeOf array<int> - maybe | ||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new IntegerType()), | ||
| TrinaryLogic::createMaybe(), | ||
| ]; | ||
|
|
||
| // array&hasOffsetValue isSubTypeOf array<string> - failure | ||
| yield [ | ||
| new IntersectionType([ | ||
| new ArrayType(new MixedType(), new MixedType()), | ||
| new NonEmptyArrayType(), | ||
| new HasOffsetValueType(new ConstantIntegerType(3), new IntegerType()), | ||
| ]), | ||
| new ArrayType(new MixedType(), new StringType()), | ||
| TrinaryLogic::createNo(), | ||
| ]; | ||
| } | ||
|
|
||
| #[DataProvider('dataIsSubTypeOf')] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.