Skip to content

Commit ef52d29

Browse files
phpstan-botclaude
andcommitted
Add TypeCombinatorTest cases for object shape intersection edge cases
Tests for: object{foo: int}&object{foo?: int}, object{foo: int}&object{foo: int|null}, object{foo: int}&object{foo?: int|null}, object{foo: int}&object{bar?: int}, and object{foo: int}&object{foo?: string}. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc8479f commit ef52d29

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/PHPStan/Type/TypeCombinatorTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,6 +4619,46 @@ public static function dataIntersect(): iterable
46194619
ObjectShapeType::class,
46204620
'object{bar: string, foo: int}',
46214621
];
4622+
yield [
4623+
[
4624+
new ObjectShapeType(['foo' => new IntegerType()], []),
4625+
new ObjectShapeType(['foo' => new IntegerType()], ['foo']),
4626+
],
4627+
ObjectShapeType::class,
4628+
'object{foo: int}',
4629+
];
4630+
yield [
4631+
[
4632+
new ObjectShapeType(['foo' => new IntegerType()], []),
4633+
new ObjectShapeType(['foo' => TypeCombinator::union(new IntegerType(), new NullType())], []),
4634+
],
4635+
ObjectShapeType::class,
4636+
'object{foo: int}',
4637+
];
4638+
yield [
4639+
[
4640+
new ObjectShapeType(['foo' => new IntegerType()], []),
4641+
new ObjectShapeType(['foo' => TypeCombinator::union(new IntegerType(), new NullType())], ['foo']),
4642+
],
4643+
ObjectShapeType::class,
4644+
'object{foo: int}',
4645+
];
4646+
yield [
4647+
[
4648+
new ObjectShapeType(['foo' => new IntegerType()], []),
4649+
new ObjectShapeType(['bar' => new IntegerType()], ['bar']),
4650+
],
4651+
ObjectShapeType::class,
4652+
'object{bar?: int, foo: int}',
4653+
];
4654+
yield [
4655+
[
4656+
new ObjectShapeType(['foo' => new IntegerType()], []),
4657+
new ObjectShapeType(['foo' => new StringType()], ['foo']),
4658+
],
4659+
NeverType::class,
4660+
'*NEVER*=implicit',
4661+
];
46224662
yield [
46234663
[
46244664
new ObjectShapeType(['foo' => new IntegerType()], []),

0 commit comments

Comments
 (0)