1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2527 - no crash when template cannot be resolved

This commit is contained in:
Matthew Brown 2019-12-29 08:45:42 -05:00
parent 0c7851ae21
commit d3fb0181cb
3 changed files with 31 additions and 3 deletions

View File

@ -1851,7 +1851,7 @@ class TypeAnalyzer
}
if (!$generic_params) {
throw new \UnexpectedValueException('$generic_params should not be empty');
return false;
}
$input_type_part = new TGenericObject(

View File

@ -340,7 +340,7 @@ class UnionTemplateHandler
}
if (!$new_generic_params) {
throw new \UnexpectedValueException('$new_generic_params should not be empty');
return new Atomic\TNamedObject($atomic_input_type->value);
}
return new Atomic\TGenericObject(

View File

@ -2716,7 +2716,7 @@ class ClassTemplateExtendsTest extends TestCase
return trim($v);
}
}'
]
],
];
}
@ -3701,6 +3701,34 @@ class ClassTemplateExtendsTest extends TestCase
}',
'error_message' => 'InvalidReturnStatement'
],
'noCrashForTooManyTemplateParams' => [
'<?php
interface InterfaceA {}
class ImplemX implements InterfaceA {}
interface DoStuff {
public function stuff(InterfaceA $object): void;
}
/**
* @implements DoStuff<ImplemX>
*/
class DoStuffX implements DoStuff {
public function stuff(InterfaceA $object): void {}
}
final class Foo {
/**
* @template A of InterfaceA
* @psalm-param DoStuff<A> $stuff
*/
public function __construct(DoStuff $stuff) {}
}
new Foo(new DoStuffX());',
'error_message' => 'InvalidArgument'
]
];
}
}