Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #17719 #17722

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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)
T-Gro marked this conversation as resolved.
Show resolved Hide resolved
| [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

T-Gro marked this conversation as resolved.
Show resolved Hide resolved
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"""]
Loading