Skip to content

Read an F# triple-quoted literal that carries no layout - #771

Merged
SimonCropp merged 2 commits into
mainfrom
fix-fs-triple-quote-inline-content
Aug 21, 2026
Merged

Read an F# triple-quoted literal that carries no layout#771
SimonCropp merged 2 commits into
mainfrom
fix-fs-triple-quote-inline-content

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

TryScanMultiLine rejected any multi-line literal whose content did not strip back to the layout convention. For C# that is right: a raw string not in that shape does not compile, so the content is something this never wrote.

F# is the other case. Its triple-quoted literal is plain verbatim text and the layout is only an agreement between the code that renders a snapshot and the code that reads one back, so a hand-written literal with its content starting on the opening line - the idiomatic shape - is perfectly valid and its value is simply what it says.

Rejecting those made them impossible to patch, and did so in the worst way: the two halves of the agreement disagreed. TryParse returned "not a string literal" while StripLayout, which is what a test library runs the value through, returned the same text unchanged, so the OriginalValue an F# producer sends as its anchor (FS0202 - no CallerArgumentExpression) could never match what the parser read. The snapshot reported "The expected argument of the call near line N is not a string literal" and stayed that way for the life of the file.

Give TryScanMultiLine a layoutRequired flag: C# passes true, F# false and falls back to the verbatim newline-normalised content, which is the answer StripLayout already gives for the same text. ParseRejectsMalformedIndent pinned the old behaviour and becomes ParseKeepsContentWithNoLayoutToStrip, which also asserts the two readers agree.

TryScanMultiLine rejected any multi-line literal whose content did not strip
back to the layout convention. For C# that is right: a raw string not in that
shape does not compile, so the content is something this never wrote.

F# is the other case. Its triple-quoted literal is plain verbatim text and the
layout is only an agreement between the code that renders a snapshot and the
code that reads one back, so a hand-written literal with its content starting on
the opening line - the idiomatic shape - is perfectly valid and its value is
simply what it says.

Rejecting those made them impossible to patch, and did so in the worst way: the
two halves of the agreement disagreed. TryParse returned "not a string literal"
while StripLayout, which is what a test library runs the value through, returned
the same text unchanged, so the OriginalValue an F# producer sends as its anchor
(FS0202 - no CallerArgumentExpression) could never match what the parser read.
The snapshot reported "The expected argument of the call near line N is not a
string literal" and stayed that way for the life of the file.

Give TryScanMultiLine a layoutRequired flag: C# passes true, F# false and falls
back to the verbatim newline-normalised content, which is the answer StripLayout
already gives for the same text. ParseRejectsMalformedIndent pinned the old
behaviour and becomes ParseKeepsContentWithNoLayoutToStrip, which also asserts
the two readers agree.
@SimonCropp
SimonCropp merged commit 11c4600 into main Aug 21, 2026
12 of 13 checks passed
@SimonCropp
SimonCropp deleted the fix-fs-triple-quote-inline-content branch August 21, 2026 23:31
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