Skip to content

Read expression types from ExpressionResults in NodeScopeResolver and handlers - #6138

Merged
ondrejmirtes merged 1 commit into
2.2.xfrom
expression-result-type-reads-4
Jul 28, 2026
Merged

Read expression types from ExpressionResults in NodeScopeResolver and handlers#6138
ondrejmirtes merged 1 commit into
2.2.xfrom
expression-result-type-reads-4

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Fourth batch of converting $scope->getType() reads to ExpressionResult reads (independent PR on 2.2.x; follows the merged batches 1–3).

  • The while pre-condition check reads $condResult->getType()/getNativeType() — the entry scope is exactly the condition result's before-scope (exact equivalence).
  • The elseif condition is processed first and its phpdoc-certain type read off the result, replacing a forward read; the native-certainty read keeps asking the outer scope, preserving the pre-existing asymmetry between the two reads.
  • Deliberately not converted: the foreach iteratee reads (they ask the post-iteratee scope) and the while/do-while post-body condition reads (they ask body-derived scopes) — those only convert with the callback world's asking-scope machinery.

Validation: full test suite green (17776 tests), self-analysis clean, code style clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_019wqGgaD7iqL44t1KgpJS7b

Comment thread src/Analyser/NodeScopeResolver.php Outdated
$this->callNodeCallback($nodeCallback, $elseif, $scope, $storage);
$elseIfConditionType = ($this->treatPhpDocTypesAsCertain ? $condScope->getType($elseif->cond) : $scope->getNativeType($elseif->cond))->toBoolean();
$condResult = $this->processExprNode($stmt, $elseif->cond, $condScope, $storage, $nodeCallback, ExpressionContext::createDeep());
$elseIfConditionType = ($this->treatPhpDocTypesAsCertain ? $condResult->getType() : $scope->getNativeType($elseif->cond))->toBoolean();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$scope->getNativeType could be $condResult->getNativeType

… handlers

Where a result is (or can be) in hand, read types off it instead of
re-asking a scope:

- the while pre-condition and the elseif condition (processed first,
  Match-style, instead of a forward read - both certainty flavours come
  off the result)
- the dynamic function-call name (processed first, then consumed for
  the parameters-acceptor selection)
- the nested array-dimension reads in offset assignments (the dims were
  already processed at that point; the reads move after the processing
  and consume the results)

The foreach iteratee and while/do-while post-body condition reads ask
post-processing scopes and stay as they are.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019wqGgaD7iqL44t1KgpJS7b
@ondrejmirtes

Copy link
Copy Markdown
Member Author

Applied — the native read now also comes off the result. Also grew the batch while at it: the dynamic function-call name is processed first and consumed for the acceptor selection, and the nested array-dimension reads in AssignHandler moved after their processing and consume the results. Full suite, self-analysis and style re-validated green.

@ondrejmirtes
ondrejmirtes force-pushed the expression-result-type-reads-4 branch from ae5a95d to a282930 Compare July 28, 2026 17:27
@ondrejmirtes ondrejmirtes changed the title Read statement condition types from ExpressionResults in NodeScopeResolver Read expression types from ExpressionResults in NodeScopeResolver and handlers Jul 28, 2026
@ondrejmirtes
ondrejmirtes merged commit e847fb4 into 2.2.x Jul 28, 2026
370 of 371 checks passed
@ondrejmirtes
ondrejmirtes deleted the expression-result-type-reads-4 branch July 28, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant