From f96e69f0641bb5702291cf3d0e6b07f6c464a4c7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 11:21:57 +0000 Subject: [PATCH 1/2] Initial plan From 150a7cd21332f6906ac286306a7847290c618c2f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 11:51:26 +0000 Subject: [PATCH 2/2] Fix SRTP get_Item witness handling for string indexers Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/c94502d3-ac80-4c41-af0e-ebfe0317394b Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- src/Compiler/TypedTree/TcGlobals.fs | 2 +- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Compiler/TypedTree/TcGlobals.fs b/src/Compiler/TypedTree/TcGlobals.fs index ef6e00ffb16..6dfbd42f98c 100644 --- a/src/Compiler/TypedTree/TcGlobals.fs +++ b/src/Compiler/TypedTree/TcGlobals.fs @@ -1929,7 +1929,7 @@ type TcGlobals( Some (g.array_get_info, [retTy], argExprs) | "set_Item", [arrTy; _; elemTy], _, [_; _; _] when isArrayTy g arrTy -> Some (g.array_set_info, [elemTy], argExprs) - | "get_Item", [stringTy; _; _], _, [_; _] when isStringTy g stringTy -> + | "get_Item", [stringTy; _], _, [_; _] when isStringTy g stringTy -> Some (g.getstring_info, [], argExprs) | "op_UnaryPlus", [aty], _, [_] -> // Call Operators.id diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 2fd70fab940..fb6c648ca49 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -287,6 +287,24 @@ let main _ = IL_000a: ret }"""] + [] + let ``SRTP get_Item works on strings`` () = + FSharp """ +let inline indexInto (slice: ^T when ^T: (member get_Item: int -> ^U)) i : ^U = + slice.get_Item i + +[] +let main _ = + if indexInto "abcde" 2 <> 'c' then + failwith "Unexpected result" + + 0 + """ + |> asExe + |> withOptions ["--nowarn:77"] + |> compileAndRun + |> shouldSucceed + [] [ string with set) >(x: 'T) = (^T : (member Item: int -> string with set) (x, 3, \"a\"))")>] [ unit) >(x: 'T) = (^T : (member set_Item: int * string -> unit) (x, 3, \"a\"))")>] @@ -699,6 +717,7 @@ let main _ = |> compileAndRun |> shouldSucceed + [] // RealSig [] // Regular [] @@ -1955,4 +1974,3 @@ if resultInt <> 0 then failwith $"Expected 0 but got {resultInt}" |> asExe |> compileAndRun |> shouldSucceed -