Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/TypedTree/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,24 @@ let main _ =
IL_000a: ret
}"""]

[<Fact>]
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

[<EntryPoint>]
let main _ =
if indexInto "abcde" 2 <> 'c' then
failwith "Unexpected result"

0
"""
|> asExe
|> withOptions ["--nowarn:77"]
|> compileAndRun
|> shouldSucceed

[<Theory>]
[<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\"))")>]
[<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\"))")>]
Expand Down Expand Up @@ -699,6 +717,7 @@ let main _ =
|> compileAndRun
|> shouldSucceed


[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down Expand Up @@ -1955,4 +1974,3 @@ if resultInt <> 0 then failwith $"Expected 0 but got {resultInt}"
|> asExe
|> compileAndRun
|> shouldSucceed

Loading