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
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