Skip to content

Commit

Permalink
Fix #1818 - handle intersection when expanding template
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 20, 2019
1 parent 5bb28cc commit a5a9da6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ private static function analyzeAtomicCall(


if ($lhs_type_part instanceof TNamedObject) { if ($lhs_type_part instanceof TNamedObject) {
$lhs_type_part->extra_types = $extra_types; $lhs_type_part->extra_types = $extra_types;
} elseif ($lhs_type_part instanceof Type\Atomic\TObject && $extra_types) {
$lhs_type_part = array_shift($extra_types);
if ($extra_types) {
$lhs_type_part->extra_types = $extra_types;
}
} }


$has_mixed_method_call = true; $has_mixed_method_call = true;
Expand Down
53 changes: 51 additions & 2 deletions tests/Template/TemplateTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2732,9 +2732,49 @@ public function foo() : void {}
} }
/** /**
* @psalm-param class-string $className * @psalm-template UnknownType
* @psalm-param class-string<UnknownType> $className
*/ */
function useMock(string $className) : void { function useMockTemplated(string $className) : void
{
mock($className)->checkExpectations();
}
mock(A::class)->foo();'
],
'allowTemplatedIntersectionFirstTemplatedMock' => [
'<?php
class MockObject
{
public function checkExpectations() : void
{
}
}
/**
* @psalm-template RequestedType
* @psalm-param class-string<RequestedType> $className
* @psalm-return RequestedType&MockObject
* @psalm-suppress MixedInferredReturnType
* @psalm-suppress MixedReturnStatement
*/
function mock(string $className)
{
eval(\'"there be dragons"\');
return $instance;
}
class A {
public function foo() : void {}
}
/**
* @psalm-template UnknownType
* @psalm-param class-string<UnknownType> $className
*/
function useMockTemplated(string $className) : void
{
mock($className)->checkExpectations(); mock($className)->checkExpectations();
} }
Expand Down Expand Up @@ -2774,6 +2814,15 @@ function useMock(string $className) : void {
mock($className)->checkExpectations(); mock($className)->checkExpectations();
} }
/**
* @psalm-template UnknownType
* @psalm-param class-string<UnknownType> $className
*/
function useMockTemplated(string $className) : void
{
mock($className)->checkExpectations();
}
mock(A::class)->foo();' mock(A::class)->foo();'
], ],
]; ];
Expand Down

0 comments on commit a5a9da6

Please sign in to comment.