-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent order of evaluation between indexing with System.Index and System.Range #57349
Comments
Was the changed order of evaluation for |
Can reproduce with .NET RC2. list = new CustomList { "first", "second", "last" };
var range = AllButLast();
Console.WriteLine(list[range]); // first second last New list = new CustomList { "first", "second", "last" };
Console.WriteLine(list[AllButLast()]); // first second Where the second example should produce |
Tagging @AlekseyTs to triage since feels like this might be related to #56611 |
Seems like the same problem but for |
Here is a quote from https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/ranges.md#adding-index-and-range-support-to-existing-library-types: The new indexer will be implemented by converting the argument of type
Therefore, Here is a quote from https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/ranges.md#implicit-range-support: When the The first argument of
This value will be re-used in the calculation of the second
The Therefore, evaluation of |
So that part of the spec suggests a different evaluation order. So clearly the spec will need to explicitly specify the evaluation order; it's just ambiguous as-is. |
I also don't think it's sane to have the order of evaluation depend on the type of the expression. In VS2019 at least it was consistent ( |
Discussed in LDM. Conclusion: Codify the expected behavior as receiver then expr then Length. |
…llow the recent LDM decision. LDM notes - https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-11-01.md. Proposed specification change - dotnet/csharplang#5380. Fixes dotnet#57349.
…llow the recent LDM decision. (#57535) LDM notes - https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-11-01.md. Proposed specification change - dotnet/csharplang#5380. Fixes #57349.
Version Used: Roslyn main (20 Oct 2021)
Steps to Reproduce:
Run the following code:
Expected Behavior:
The methods
AllButLast
/Last
should be called before the indexing operator retrieveslist.Count
.Console.WriteLine(list[AllButLast()])
should outputfirst, second, last, New
.Console.WriteLine(list[Last()]);
should outputNewLast
.Actual Behavior:
VS2019 retrieves
list.Count
before callingAllButLast
/Last
, output:Roslyn main (20 Oct 2021) retrieves
list.Count
before callingAllButLast
, but after callingLast
, output:See on SharpLab
The text was updated successfully, but these errors were encountered: