Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Compiler/SyntaxTree/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,11 @@ type LexFilterImpl (
| INTERP_STRING_PART _ ->
pushCtxt tokenTup (CtxtParen (token, tokenTup.LexbufState.EndPos))
pushCtxtSeqBlock tokenTup NoAddBlockEnd
| INTERP_STRING_END _ -> ()
| _ ->
// Queue a dummy token at this position to check if any closing rules apply
delayToken(pool.UseLocation(tokenTup, ODUMMY token))

returnToken tokenLexbufState token

// Balancing rule. Encountering a 'end' can balance with a 'with' but only when not offside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,23 @@ let s = $"...%-%...{0}"
"""
|> compile
|> shouldFail
|> withSingleDiagnostic (Warning 3376, Line 2, Col 9, Line 2, Col 24, "Bad format specifier: '%'")
|> withSingleDiagnostic (Warning 3376, Line 2, Col 9, Line 2, Col 24, "Bad format specifier: '%'")

[<Fact>]
let ``Interpolated expression can be offside`` () =
Fsx """
let a() =
let b() =
$"
{1}"
b()

type Foo () =
member _.Bar () =
let x =
$"
{2}"
x
"""
|> compile
|> shouldSucceed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A =
let b =
$"
{0}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ImplFile
(ParsedImplFileInput
("/root/String/InterpolatedStringOffsideInModule.fs", false,
QualifiedNameOfFile InterpolatedStringOffsideInModule, [], [],
[SynModuleOrNamespace
([InterpolatedStringOffsideInModule], false, AnonModule,
[NestedModule
(SynComponentInfo
([], None, [], [A],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), false,
None, (1,0--1,8)), false,
[Let
(false,
[SynBinding
(None, Normal, false, false, [],
PreXmlDoc ((2,4), FSharp.Compiler.Xml.XmlDocCollector),
SynValData
(None, SynValInfo ([], SynArgInfo ([], false, None)),
None),
Named (SynIdent (b, None), false, None, (2,8--2,9)), None,
InterpolatedString
([String ("
", (3,8--4,1));
FillExpr (Const (Int32 0, (4,1--4,2)), None);
String ("", (4,2--4,4))], Regular, (3,8--4,4)),
(2,8--2,9), Yes (2,4--4,4),
{ LeadingKeyword = Let (2,4--2,7)
InlineKeyword = None
EqualsRange = Some (2,10--2,11) })], (2,4--4,4))], false,
(1,0--4,4), { ModuleKeyword = Some (1,0--1,6)
EqualsRange = Some (1,9--1,10) })], PreXmlDocEmpty,
[], None, (1,0--4,4), { LeadingKeyword = None })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let a =
let b =
$"
{0}"
b
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ImplFile
(ParsedImplFileInput
("/root/String/InterpolatedStringOffsideInNestedLet.fs", false,
QualifiedNameOfFile InterpolatedStringOffsideInNestedLet, [], [],
[SynModuleOrNamespace
([InterpolatedStringOffsideInNestedLet], false, AnonModule,
[Let
(false,
[SynBinding
(None, Normal, false, false, [],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector),
SynValData
(None, SynValInfo ([], SynArgInfo ([], false, None)), None),
Named (SynIdent (a, None), false, None, (1,4--1,5)), None,
LetOrUse
(false, false,
[SynBinding
(None, Normal, false, false, [],
PreXmlDoc ((2,4), FSharp.Compiler.Xml.XmlDocCollector),
SynValData
(None, SynValInfo ([], SynArgInfo ([], false, None)),
None),
Named (SynIdent (b, None), false, None, (2,8--2,9)),
None,
InterpolatedString
([String ("
", (3,8--4,1));
FillExpr (Const (Int32 0, (4,1--4,2)), None);
String ("", (4,2--4,4))], Regular, (3,8--4,4)),
(2,8--2,9), Yes (2,4--4,4),
{ LeadingKeyword = Let (2,4--2,7)
InlineKeyword = None
EqualsRange = Some (2,10--2,11) })], Ident b,
(2,4--5,5), { InKeyword = None }), (1,4--1,5), NoneAtLet,
{ LeadingKeyword = Let (1,0--1,3)
InlineKeyword = None
EqualsRange = Some (1,6--1,7) })], (1,0--5,5))],
PreXmlDocEmpty, [], None, (1,0--5,5), { LeadingKeyword = None })],
(true, true), { ConditionalDirectives = []
CodeComments = [] }, set []))