mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Don’t throw an exceptin when parsing invalid type
This commit is contained in:
parent
196f24aac3
commit
686f9fcaaa
@ -185,7 +185,11 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
$assertion = 'class-string';
|
||||
}
|
||||
|
||||
$new_type = Type::parseString($assertion, null, $template_type_map);
|
||||
try {
|
||||
$new_type = Type::parseString($assertion, null, $template_type_map);
|
||||
} catch (\Psalm\Exception\TypeParseTreeException $e) {
|
||||
$new_type = Type::getMixed();
|
||||
}
|
||||
}
|
||||
|
||||
if ($existing_var_type->hasMixed()) {
|
||||
|
@ -986,6 +986,26 @@ class FunctionTemplateAssertTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'string, string',
|
||||
],
|
||||
'noCrashWhenOnUnparseableTemplatedAssertion' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template TCandidateKey as array-key
|
||||
* @param array $arr
|
||||
* @param TCandidateKey $key
|
||||
* @psalm-assert has-array-key<TCandidateKey> $arr
|
||||
*/
|
||||
function keyExists(array $arr, $key) : void {
|
||||
if (!array_key_exists($key, $arr)) {
|
||||
throw new \Exception("bad");
|
||||
}
|
||||
}
|
||||
|
||||
function fromArray(array $data) : void {
|
||||
keyExists($data, "id");
|
||||
if (is_string($data["id"])) {}
|
||||
}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user