Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vzarytovskii committed Sep 13, 2024
1 parent aea757f commit 00a8ee9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7530,9 +7530,9 @@ and TcInterpolatedStringExpr cenv (overallTy: OverallTy) env m tpenv (parts: Syn
let concatenableExprs = if canLower then concatenable [] fillExprs parts else []

match concatenableExprs with
| [p1; p2; p3; p4] -> mkStaticCall_String_Concat4 g m p1 p2 p3 p4, tpenv
| [p1; p2; p3] -> mkStaticCall_String_Concat3 g m p1 p2 p3, tpenv
| [p1; p2] -> mkStaticCall_String_Concat2 g m p1 p2, tpenv
| [p1; p2; p3; p4] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat4 g m p1 p2 p3 p4, tpenv)
| [p1; p2; p3] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat3 g m p1 p2 p3, tpenv)
| [p1; p2] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat2 g m p1 p2, tpenv)
| [p1] -> p1, tpenv
| _ ->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,46 @@ IL_0014: call string [runtime]System.String::Concat(string,
string,
string,
string)
IL_0019: ret"""]
IL_0019: ret"""]

[<Fact>]
let ``Interpolated string with concat converts to span implicitly`` () =
let compilation =
FSharp $"""
module InterpolatedStringByefLikes
type Foo() =
let sb = System.Text.StringBuilder()
member _.Bar(s: System.ReadOnlySpan<char>) = sb.Append(s) |> ignore
let [<EntryPoint>] main _ =
let foo = Foo()
let foos = "foo"
foo.Bar($"{{foos}} is bar")
0
"""

compilation |> compile |> shouldSucceed |> ignore

compilation |> asExe |> compileAndRun |> shouldSucceed |> ignore

compilation |> compile |> shouldSucceed |> verifyIL ["""
.locals init (class InterpolatedStringByefLikes/Foo V_0,
valuetype [runtime]System.ReadOnlySpan`1<char> V_1,
class [runtime]System.Text.StringBuilder V_2)
IL_0000: newobj instance void InterpolatedStringByefLikes/Foo::.ctor()
IL_0005: stloc.0
IL_0006: ldstr "foo"
IL_000b: ldstr " is bar"
IL_0010: call string [runtime]System.String::Concat(string,
string)
IL_0015: call valuetype [runtime]System.ReadOnlySpan`1<char> [runtime]System.String::op_Implicit(string)
IL_001a: stloc.1
IL_001b: ldloc.0
IL_001c: ldfld class [runtime]System.Text.StringBuilder InterpolatedStringByefLikes/Foo::sb
IL_0021: ldloc.1
IL_0022: callvirt instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(valuetype [runtime]System.ReadOnlySpan`1<char>)
IL_0027: stloc.2
IL_0028: ldc.i4.0
IL_0029: ret"""]

0 comments on commit 00a8ee9

Please sign in to comment.