Skip to content

Commit c910057

Browse files
authored
Fix #17719 (#17722)
* Fix #17719 * Only run test in netcoreapp
1 parent ddc90b8 commit c910057

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7530,9 +7530,9 @@ and TcInterpolatedStringExpr cenv (overallTy: OverallTy) env m tpenv (parts: Syn
75307530
let concatenableExprs = if canLower then concatenable [] fillExprs parts else []
75317531

75327532
match concatenableExprs with
7533-
| [p1; p2; p3; p4] -> mkStaticCall_String_Concat4 g m p1 p2 p3 p4, tpenv
7534-
| [p1; p2; p3] -> mkStaticCall_String_Concat3 g m p1 p2 p3, tpenv
7535-
| [p1; p2] -> mkStaticCall_String_Concat2 g m p1 p2, tpenv
7533+
| [p1; p2; p3; p4] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat4 g m p1 p2 p3 p4, tpenv)
7534+
| [p1; p2; p3] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat3 g m p1 p2 p3, tpenv)
7535+
| [p1; p2] -> TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env m (fun () -> mkStaticCall_String_Concat2 g m p1 p2, tpenv)
75367536
| [p1] -> p1, tpenv
75377537
| _ ->
75387538

tests/FSharp.Compiler.ComponentTests/EmittedIL/StringFormatAndInterpolation.fs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,46 @@ IL_0014: call string [runtime]System.String::Concat(string,
8888
string,
8989
string,
9090
string)
91-
IL_0019: ret"""]
91+
IL_0019: ret"""]
92+
93+
[<FSharp.Test.FactForNETCOREAPP>]
94+
let ``Interpolated string with concat converts to span implicitly`` () =
95+
let compilation =
96+
FSharp $"""
97+
module InterpolatedStringByefLikes
98+
type Foo() =
99+
100+
let sb = System.Text.StringBuilder()
101+
102+
member _.Bar(s: System.ReadOnlySpan<char>) = sb.Append(s) |> ignore
103+
104+
let [<EntryPoint>] main _ =
105+
let foo = Foo()
106+
let foos = "foo"
107+
foo.Bar($"{{foos}} is bar")
108+
0
109+
"""
110+
111+
compilation |> compile |> shouldSucceed |> ignore
112+
113+
compilation |> asExe |> compileAndRun |> shouldSucceed |> ignore
114+
115+
compilation |> compile |> shouldSucceed |> verifyIL ["""
116+
.locals init (class InterpolatedStringByefLikes/Foo V_0,
117+
valuetype [runtime]System.ReadOnlySpan`1<char> V_1,
118+
class [runtime]System.Text.StringBuilder V_2)
119+
IL_0000: newobj instance void InterpolatedStringByefLikes/Foo::.ctor()
120+
IL_0005: stloc.0
121+
IL_0006: ldstr "foo"
122+
IL_000b: ldstr " is bar"
123+
IL_0010: call string [runtime]System.String::Concat(string,
124+
string)
125+
IL_0015: call valuetype [runtime]System.ReadOnlySpan`1<char> [runtime]System.String::op_Implicit(string)
126+
IL_001a: stloc.1
127+
IL_001b: ldloc.0
128+
IL_001c: ldfld class [runtime]System.Text.StringBuilder InterpolatedStringByefLikes/Foo::sb
129+
IL_0021: ldloc.1
130+
IL_0022: callvirt instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(valuetype [runtime]System.ReadOnlySpan`1<char>)
131+
IL_0027: stloc.2
132+
IL_0028: ldc.i4.0
133+
IL_0029: ret"""]

0 commit comments

Comments
 (0)