1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #5518 - add type for property with variable name

This commit is contained in:
Matt Brown 2021-04-25 14:49:43 -04:00
parent daa40281df
commit 7b7354efa3
2 changed files with 25 additions and 0 deletions

View File

@ -204,6 +204,19 @@ class InstancePropertyFetchAnalyzer
}
}
$statements_analyzer->node_data->setType($stmt, Type::getMixed());
if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
) {
$codebase->analyzer->addNodeType(
$statements_analyzer->getFilePath(),
$stmt->name,
$stmt_var_type->getId()
);
}
return true;
}

View File

@ -2365,6 +2365,18 @@ class UnusedVariableTest extends TestCase
}
}'
],
'concatWithUnknownProperty' => [
'<?php
/** @param array<string> $key */
function foo(object $a, string $k) : string {
$sortA = "";
/** @psalm-suppress MixedOperand */
$sortA .= $a->$k;
return $sortA;
}'
],
];
}