Skip to content

Read an interpolation format specifier as text, not code [patch] - #168

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/issue-165-format-specifier-not-comment
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/issue-165-format-specifier-not-comment

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #165

Summary

VerbatimStringScanner treated everything inside an interpolation hole as code. So the // in {d:yyyy//MM} started a line comment, and that comment swallowed the hole's } and the string's closing ". Both fixes that rely on the scanner then went wrong:

The fix is in ScanCode. While inside a hole, it now tracks (/[ depth alongside the existing { depth. A : at depth 0 starts the format specifier, provided it is not part of a :: alias qualifier. The format specifier is skipped as literal text up to the hole's closing }. A conditional ? : and a named argument are always nested inside parentheses, so their colons are not mistaken for one. SkipInterpolationHole now consumes the next character only when it really is a }, so a malformed fragment cannot have a line break eaten.

Tests


Generated by Claude Code

VerbatimStringScanner walked everything inside an interpolation hole as
code, so the `//` in `{d:yyyy//MM}` started a line comment that swallowed
the hole's closing brace and the string's closing quote. An expression
body then got its semicolon inside a trailing comment (CS1002), and a
verbatim string's continuation lines were re-indented.

A colon outside every nested parenthesis, bracket and brace in a hole,
and not part of a `::` alias qualifier, now starts the format specifier,
which is skipped as literal text up to the hole's closing brace.

Fixes #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3PT52Zo3M7fFP8Z6J
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 08f896f into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the claude/issue-165-format-specifier-not-comment branch November 4, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants