mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #3443 - add InvalidDocblock issue for @psalm-assert Foo|!Bar
This commit is contained in:
parent
a198b09eb7
commit
15e753e279
@ -2830,17 +2830,27 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
? $this->class_template_types
|
||||
: [];
|
||||
|
||||
$namespaced_type = TypeParser::parseTokens(
|
||||
TypeTokenizer::getFullyQualifiedTokens(
|
||||
$assertion_type,
|
||||
$this->aliases,
|
||||
$this->function_template_types + $class_template_types,
|
||||
$this->type_aliases,
|
||||
null,
|
||||
null,
|
||||
true
|
||||
)
|
||||
);
|
||||
try {
|
||||
$namespaced_type = TypeParser::parseTokens(
|
||||
TypeTokenizer::getFullyQualifiedTokens(
|
||||
$assertion_type,
|
||||
$this->aliases,
|
||||
$this->function_template_types + $class_template_types,
|
||||
$this->type_aliases,
|
||||
null,
|
||||
null,
|
||||
true
|
||||
)
|
||||
);
|
||||
} catch (TypeParseTreeException $e) {
|
||||
$storage->docblock_issues[] = new InvalidDocblock(
|
||||
'Invalid @psalm-assert union type ' . $e,
|
||||
new CodeLocation($this->file_scanner, $stmt, null, true)
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if ($prefix && count($namespaced_type->getAtomicTypes()) > 1) {
|
||||
$storage->docblock_issues[] = new InvalidDocblock(
|
||||
|
@ -505,7 +505,7 @@ class AssertAnnotationTest extends TestCase
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @psalm-assert BarType $this
|
||||
*/
|
||||
@ -514,7 +514,7 @@ class AssertAnnotationTest extends TestCase
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function takesType(Type $t) : void {
|
||||
$t->assertFoo();
|
||||
$t->assertBar();
|
||||
@ -1361,6 +1361,16 @@ class AssertAnnotationTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'UndefinedMethod',
|
||||
],
|
||||
'invalidUnionAssertion' => [
|
||||
'<?php
|
||||
interface I {
|
||||
/**
|
||||
* @psalm-assert null|!ExpectedType $value
|
||||
*/
|
||||
public static function foo($value);
|
||||
}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user