Skip to content

Commit

Permalink
Merge pull request #10264 from robchett/support_aliases_for_check_type
Browse files Browse the repository at this point in the history
Add alias support to psalm-check-type
  • Loading branch information
orklah committed Oct 8, 2023
2 parents 69d5881 + d874aab commit b65e095
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Expand Up @@ -678,7 +678,11 @@ private static function analyzeStatement(
} else {
try {
$checked_type = $context->vars_in_scope[$checked_var_id];
$check_type = Type::parseString($check_type_string);
$fq_check_type_string = Type::getFQCLNFromString(
$check_type_string,
$statements_analyzer->getAliases(),
);
$check_type = Type::parseString($fq_check_type_string);
/** @psalm-suppress InaccessibleProperty We just created this type */
$check_type->possibly_undefined = $possibly_undefined;

Expand Down
20 changes: 20 additions & 0 deletions tests/CheckTypeTest.php
Expand Up @@ -18,6 +18,26 @@ public function providerValidCodeParse(): iterable
$foo = 1;
',
];
yield 'allowNamespace' => [
'code' => '<?php
namespace X;
final class A {}
$_a = new A();
/** @psalm-check-type-exact $_a = A */',
];
yield 'allowImport' => [
'code' => '<?php
namespace X;
use \stdClass;
$_a = new stdClass();
/** @psalm-check-type-exact $_a = \stdClass */',
];
}

public function providerInvalidCodeParse(): iterable
Expand Down

0 comments on commit b65e095

Please sign in to comment.