diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index 7d4162f804e..59e76638ae3 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -56,6 +56,7 @@ * Fix parallel compilation of scripts ([PR #19649](https://github.com/dotnet/fsharp/pull/19649)) * Fix parser recovery, name resolution, and code completion for unfinished enum patterns ([PR #19708](https://github.com/dotnet/fsharp/pull/19708)) * Parser: fix unexpected diagnostics in debug builds, improve error messages ([PR #19730](https://github.com/dotnet/fsharp/pull/19730)) +* Fix internal error when resolving SRTP `get_Item` witness for `string` indexers (`unknown builtin witness 'get_ItemDynamic'`). ([Issue #18093](https://github.com/dotnet/fsharp/issues/18093), [PR #19757](https://github.com/dotnet/fsharp/pull/19757)) * Fix signature conformance: overloaded member with unit parameter `M(())` now matches sig `member M: unit -> unit`. ([Issue #19596](https://github.com/dotnet/fsharp/issues/19596), [PR #19615](https://github.com/dotnet/fsharp/pull/19615)) ### Added 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 -