From ab69dbeb639c45771e226ce1900f2acdda05f697 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Fri, 20 Jun 2025 16:30:26 +0200 Subject: [PATCH] fix: skip zero-width error tokens in last_non_whitespace_byte to ensure that `let x = 1 # comment` is treated as an incomplete expression --- src/core/parse_stream.jl | 5 +++-- test/hooks.jl | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/parse_stream.jl b/src/core/parse_stream.jl index fd66b2b4..d82a601f 100644 --- a/src/core/parse_stream.jl +++ b/src/core/parse_stream.jl @@ -970,10 +970,11 @@ function last_non_whitespace_byte(stream::ParseStream) for i = length(stream.output):-1:1 node = stream.output[i] if is_terminal(node) - if !(kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment") + if kind(node) in KSet"Comment Whitespace NewlineWs ErrorEofMultiComment" || kind(node) == K"error" && node.byte_span == 0 + byte_pos -= node.byte_span + else return byte_pos - 1 end - byte_pos -= node.byte_span end end return first_byte(stream) - 1 diff --git a/test/hooks.jl b/test/hooks.jl index c41d2dac..333344d7 100644 --- a/test/hooks.jl +++ b/test/hooks.jl @@ -497,6 +497,7 @@ end "Issue53126()." => :other "using " => :other "global xxx::Number = Base." => :other + "let x = 1 # comment" => :other ] @testset "$(repr(str))" begin # Test :statement parsing