Skip to content

Do not swallow a trailing comment into the argument - #783

Merged
SimonCropp merged 1 commit into
mainfrom
fix-patcher-trailing-comment
Aug 22, 2026
Merged

Do not swallow a trailing comment into the argument#783
SimonCropp merged 1 commit into
mainfrom
fix-patcher-trailing-comment

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

TrimSpan's trailing loop trimmed whitespace before asking whether a comment
ended where it was looking. A line comment's span includes the newline that ends
it, so the first thing trimmed was that newline - after which nothing ended at
end any more, the comment check never matched, and the comment stayed inside
the argument span.

The argument then was not a string literal, and the snapshot could not be
patched at all: "The expected argument of the Snapshot call near line N is not a
string literal", for a call that is perfectly ordinary apart from having a
comment after it.

Ask about the comment first. The two cases only collide when a comment ends
exactly where the scan is looking and the character before it is that comment's
own newline, which is precisely the shape that failed.

TrimSpan's trailing loop trimmed whitespace before asking whether a comment
ended where it was looking. A line comment's span includes the newline that ends
it, so the first thing trimmed was that newline - after which nothing ended at
`end` any more, the comment check never matched, and the comment stayed inside
the argument span.

The argument then was not a string literal, and the snapshot could not be
patched at all: "The expected argument of the Snapshot call near line N is not a
string literal", for a call that is perfectly ordinary apart from having a
comment after it.

Ask about the comment first. The two cases only collide when a comment ends
exactly where the scan is looking and the character before it is that comment's
own newline, which is precisely the shape that failed.
@SimonCropp
SimonCropp merged commit 355c7fb into main Aug 22, 2026
9 checks passed
@SimonCropp
SimonCropp deleted the fix-patcher-trailing-comment branch August 22, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant