diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php index 94771ed2e..790b36b30 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php @@ -134,12 +134,26 @@ final class StaticPropertyFetchAnalyzer if ($stmt->name instanceof PhpParser\Node\VarLikeIdentifier) { $prop_name = $stmt->name->name; - } elseif (($stmt_name_type = $statements_analyzer->node_data->getType($stmt->name)) - && $stmt_name_type->isSingleStringLiteral() - ) { - $prop_name = $stmt_name_type->getSingleStringLiteral()->value; } else { - $prop_name = null; + $was_inside_general_use = $context->inside_general_use; + + $context->inside_general_use = true; + + if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->name, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + + return false; + } + + $context->inside_general_use = $was_inside_general_use; + + if (($stmt_name_type = $statements_analyzer->node_data->getType($stmt->name)) + && $stmt_name_type->isSingleStringLiteral() + ) { + $prop_name = $stmt_name_type->getSingleStringLiteral()->value; + } else { + $prop_name = null; + } } if (!$prop_name) { diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index 8518dd510..d58c210c0 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -1012,7 +1012,7 @@ class UnusedVariableTest extends TestCase A::$method(); }', ], - 'usedAsStaticPropertyName' => [ + 'usedAsStaticPropertyAssign' => [ 'code' => ' [ + 'code' => ' [ 'code' => '