Skip to content

Commit

Permalink
Merge pull request #8705 from annervisser/add-support-for-type-aliase…
Browse files Browse the repository at this point in the history
…s-in-psalm-assert-annotations

Fixes #8263
  • Loading branch information
weirdan committed Nov 14, 2022
2 parents 56bc854 + dd253b7 commit 2a29fd7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Expand Up @@ -615,7 +615,8 @@ private static function getAssertionParts(
true
),
null,
$template_types
$template_types,
$type_aliases
);
} catch (TypeParseTreeException $e) {
$storage->docblock_issues[] = new InvalidDocblock(
Expand Down
37 changes: 37 additions & 0 deletions tests/TypeAnnotationTest.php
Expand Up @@ -593,6 +593,43 @@ class C extends A {}
'$output' => 'string',
],
],
'importedTypeUsedInAssertion' => [
'code' => '<?php
/** @psalm-type Foo = string */
class A {}
/**
* @psalm-immutable
* @psalm-import-type Foo from A as FooAlias
*/
class B {
/**
* @param mixed $input
* @psalm-return FooAlias
*/
public function convertToFoo($input) {
$this->assertFoo($input);
return $input;
}
/**
* @param mixed $value
* @psalm-assert FooAlias $value
*/
private function assertFoo($value): void {
if(!is_string($value)) {
throw new \InvalidArgumentException();
}
}
}
$instance = new B();
$output = $instance->convertToFoo("hallo");
',
'assertions' => [
'$output' => 'string',
]
]
];
}

Expand Down

0 comments on commit 2a29fd7

Please sign in to comment.