Skip to content

Commit

Permalink
From stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 25, 2024
1 parent b3ab2a5 commit 208644c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,10 @@ public static function analyzeAssignmentOperation(
public static function analyzeAssignmentRef(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\AssignRef $stmt,
Context $context
Context $context,
?PhpParser\Node\Stmt $from_stmt
): bool {
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, false, null, true);
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, null, null, true);

$lhs_var_id = ExpressionIdentifier::getExtendedVarId(
$stmt->var,
Expand All @@ -912,7 +913,7 @@ public static function analyzeAssignmentRef(
$statements_analyzer,
);

$doc_comment = $stmt->getDocComment();
$doc_comment = $stmt->getDocComment() ?? ($from_stmt ? $from_stmt->getDocComment() : null);
if ($doc_comment) {
try {
$var_comments = CommentAnalyzer::getTypeFromComment(
Expand Down
12 changes: 6 additions & 6 deletions src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function analyze(
Context $context,
bool $array_assignment = false,
?Context $global_context = null,
bool $from_stmt = false,
?PhpParser\Node\Stmt $from_stmt = null,
?TemplateResult $template_result = null,
bool $assigned_to_reference = false
): bool {
Expand Down Expand Up @@ -183,7 +183,7 @@ private static function handleExpression(
Context $context,
bool $array_assignment,
?Context $global_context,
bool $from_stmt,
?PhpParser\Node\Stmt $from_stmt,
?TemplateResult $template_result = null,
bool $assigned_to_reference = false
): bool {
Expand Down Expand Up @@ -293,7 +293,7 @@ private static function handleExpression(
$stmt,
$context,
0,
$from_stmt,
$from_stmt !== null,
);
}

Expand Down Expand Up @@ -380,7 +380,7 @@ private static function handleExpression(
}

if ($stmt instanceof PhpParser\Node\Expr\AssignRef) {
if (!AssignmentAnalyzer::analyzeAssignmentRef($statements_analyzer, $stmt, $context)) {
if (!AssignmentAnalyzer::analyzeAssignmentRef($statements_analyzer, $stmt, $context, $from_stmt)) {
IssueBuffer::maybeAdd(
new UnsupportedReferenceUsage(
"This reference cannot be analyzed by Psalm",
Expand Down Expand Up @@ -499,15 +499,15 @@ private static function analyzeAssignment(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr $stmt,
Context $context,
bool $from_stmt
?PhpParser\Node\Stmt $from_stmt
): bool {
$assignment_type = AssignmentAnalyzer::analyze(
$statements_analyzer,
$stmt->var,
$stmt->expr,
null,
$context,
$stmt->getDocComment(),
$stmt->getDocComment() ?? ($from_stmt ? $from_stmt->getDocComment() : null),
[],
!$from_stmt ? $stmt : null,
);
Expand Down

0 comments on commit 208644c

Please sign in to comment.