mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Support user defined types for psalm-check-type
This commit is contained in:
parent
526013e77e
commit
9d4fd4011d
@ -680,16 +680,21 @@ final class StatementsAnalyzer extends SourceAnalyzer
|
||||
} else {
|
||||
try {
|
||||
$checked_type = $context->vars_in_scope[$checked_var_id];
|
||||
|
||||
$path = $statements_analyzer->getRootFilePath();
|
||||
$file_storage = $codebase->file_storage_provider->get($path);
|
||||
|
||||
$check_tokens = TypeTokenizer::getFullyQualifiedTokens(
|
||||
$check_type_string,
|
||||
$statements_analyzer->getAliases(),
|
||||
$statements_analyzer->getTemplateTypeMap(),
|
||||
$file_storage->type_aliases,
|
||||
);
|
||||
$check_type = TypeParser::parseTokens(
|
||||
$check_tokens,
|
||||
null,
|
||||
$statements_analyzer->getTemplateTypeMap() ?? [],
|
||||
[],
|
||||
$file_storage->type_aliases,
|
||||
true,
|
||||
);
|
||||
/** @psalm-suppress InaccessibleProperty We just created this type */
|
||||
|
@ -38,6 +38,15 @@ class CheckTypeTest extends TestCase
|
||||
$_a = new stdClass();
|
||||
/** @psalm-check-type-exact $_a = \stdClass */',
|
||||
];
|
||||
yield 'allowType' => [
|
||||
'code' => '<?php
|
||||
namespace X;
|
||||
|
||||
/** @psalm-type A = int|string */
|
||||
|
||||
$_a = 1;
|
||||
/** @psalm-check-type $_a = A */',
|
||||
];
|
||||
}
|
||||
|
||||
public function providerInvalidCodeParse(): iterable
|
||||
|
Loading…
Reference in New Issue
Block a user