diff --git a/src/Resolution/VariableBindings.php b/src/Resolution/VariableBindings.php index 503ee412..73afe18b 100644 --- a/src/Resolution/VariableBindings.php +++ b/src/Resolution/VariableBindings.php @@ -94,11 +94,13 @@ private static function walk(array $stmts, int $offset, Scope $scope, array &$bi continue; } - // PHP assigns after evaluating the right side, which may read the earlier binding. + // File positions are inclusive, while a cursor offset is between characters. + // A cursor immediately after the expression can still be in its right-hand side, + // so the assignment only binds once it is beyond the expression's end position. if ( $stmt instanceof Stmt\Expression && $stmt->expr instanceof Assign - && $stmt->expr->getEndFilePos() < $offset + && $stmt->expr->getEndFilePos() + 1 < $offset ) { self::bind($stmt->expr->var, $scope, $bindings); } diff --git a/tests/EndToEnd/defects/assignment-target-offered-while-typing.php b/tests/EndToEnd/scripts/assignment-target-offered-while-typing.php similarity index 100% rename from tests/EndToEnd/defects/assignment-target-offered-while-typing.php rename to tests/EndToEnd/scripts/assignment-target-offered-while-typing.php