Skip to content
Permalink
Browse files

Fix #1818 - handle intersection when expanding template

  • Loading branch information...
muglug committed Jun 20, 2019
1 parent 5bb28cc commit a5a9da6e507493c704d5155c66db14bd92ff2c12
@@ -422,6 +422,11 @@ private static function analyzeAtomicCall(
if ($lhs_type_part instanceof TNamedObject) {
$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;
@@ -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();
}
@@ -2774,6 +2814,15 @@ function useMock(string $className) : void {
mock($className)->checkExpectations();
}
/**
* @psalm-template UnknownType
* @psalm-param class-string<UnknownType> $className
*/
function useMockTemplated(string $className) : void
{
mock($className)->checkExpectations();
}
mock(A::class)->foo();'
],
];

0 comments on commit a5a9da6

Please sign in to comment.
You can’t perform that action at this time.