Skip to content

Commit c0bc8de

Browse files
authored
Fix SRTP get_Item witness resolution for string indexers (dotnet#19757)
1 parent a62e57b commit c0bc8de

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
* Fix parallel compilation of scripts ([PR #19649](https://github.com/dotnet/fsharp/pull/19649))
6262
* Fix parser recovery, name resolution, and code completion for unfinished enum patterns ([PR #19708](https://github.com/dotnet/fsharp/pull/19708))
6363
* Parser: fix unexpected diagnostics in debug builds, improve error messages ([PR #19730](https://github.com/dotnet/fsharp/pull/19730))
64+
* 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))
6465
* Allow `| null` nullable annotation on a `[<MeasureAnnotatedAbbreviation>]` over a reference type (e.g. the FSharp.UMX `type string<[<Measure>] 'm> = string` pattern). ([Issue #19657](https://github.com/dotnet/fsharp/issues/19657))
6566
* Fix `[<Struct>] ?param` optional parameters could not be passed using the explicit `?param = expr` caller-side syntax with a `ValueOption` value. ([Issue #19711](https://github.com/dotnet/fsharp/issues/19711), [PR #19742](https://github.com/dotnet/fsharp/pull/19742))
6667
* 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))

src/Compiler/TypedTree/TcGlobals.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ type TcGlobals(
19291929
Some (g.array_get_info, [retTy], argExprs)
19301930
| "set_Item", [arrTy; _; elemTy], _, [_; _; _] when isArrayTy g arrTy ->
19311931
Some (g.array_set_info, [elemTy], argExprs)
1932-
| "get_Item", [stringTy; _; _], _, [_; _] when isStringTy g stringTy ->
1932+
| "get_Item", [stringTy; _], _, [_; _] when isStringTy g stringTy ->
19331933
Some (g.getstring_info, [], argExprs)
19341934
| "op_UnaryPlus", [aty], _, [_] ->
19351935
// Call Operators.id

tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ let main _ =
287287
IL_000a: ret
288288
}"""]
289289

290+
[<Fact>]
291+
let ``SRTP get_Item works on strings`` () =
292+
FSharp """
293+
let inline indexInto (slice: ^T when ^T: (member get_Item: int -> ^U)) i : ^U =
294+
slice.get_Item i
295+
296+
[<EntryPoint>]
297+
let main _ =
298+
if indexInto "abcde" 2 <> 'c' then
299+
failwith "Unexpected result"
300+
301+
0
302+
"""
303+
|> asExe
304+
|> withOptions ["--nowarn:77"]
305+
|> compileAndRun
306+
|> shouldSucceed
307+
290308
[<Theory>]
291309
[<InlineData("let inline f_set_Item<'T when 'T : (member Item: int -> string with set) >(x: 'T) = (^T : (member Item: int -> string with set) (x, 3, \"a\"))")>]
292310
[<InlineData("let inline f_set_Item<'T when 'T : (member set_Item: int * string -> unit) >(x: 'T) = (^T : (member set_Item: int * string -> unit) (x, 3, \"a\"))")>]
@@ -699,6 +717,7 @@ let main _ =
699717
|> compileAndRun
700718
|> shouldSucceed
701719

720+
702721
[<InlineData(true)>] // RealSig
703722
[<InlineData(false)>] // Regular
704723
[<Theory>]
@@ -1955,4 +1974,3 @@ if resultInt <> 0 then failwith $"Expected 0 but got {resultInt}"
19551974
|> asExe
19561975
|> compileAndRun
19571976
|> shouldSucceed
1958-

0 commit comments

Comments
 (0)