SRTP "member get_Item" causes "FS0192: internal error" when used on strings #18093
Labels
Area-Compiler-SRTP
bugs in SRTP inference, resolution, witness passing, code gen
Bug
Impact-Low
(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
Please provide a succinct description of the issue.
I was attempting to index into array-like collections using SRTP and encountered the error using strings. It appears the underlying cause is that the indexer method is not necessarily
get_Item
and may be overridden using[<IndexerName>]
. This is the case in String.cs with the attribute[IndexerName("Chars")]
that results in aget_Chars
method instead ofget_Item
.Provide the steps required to reproduce the problem:
It can be reproduced using FSI
Expected behavior
My initial expectation was that
indexInto
would allow indexing into any type that had an indexer (using eitherget_Item
or[i]
) but after learning about[<IndexerName>]
I'm no longer sure if this should be the case. Some suggestions for a resolution:member get_Item
in SRTPMake
get_Item
a compiler-known method that checks for usage of[<IndexerName>]
on the target type and inserts the appropriate call.Despite being "magical" this is probably the expected behavior of most F# developers unaware of the existence of
[<IndexerName>]
.The error should become "The type 'string' does not support the operator 'get_Item'" rather than "FS0192 internal error" to match other type errors.
Consider some other syntax to allow indexers to be accessed for all types using SRTP:
member []
member Item[]
[<Indexer>] member get_Item
member op_Item
Known workarounds
String
doesn't implementIReadOnlyList
which would seem appropriate for this case)Span
which unifies some indexable types but has other usage limitationsThe text was updated successfully, but these errors were encountered: