-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Allow foreach with string even if string does not implement foreach pattern. #11401
Conversation
…attern. Similarly to arrays and dynamic, we use IEnumerable pattern for binding purposes and then ignore that in emit by using a custom lowering strategy. Fixes dotnet#11387
@dotnet-bot retest prtest/win/dbg/unit32 please |
@dotnet-bot retest prtest/win/dbg/unit64 please |
@dotnet/roslyn-compiler please review |
public int Length => 2; | ||
|
||
[System.Runtime.CompilerServices.IndexerName(""Chars"")] | ||
public char this[int i] => 'a'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are IndexerNameAttribute
and DefaultMemberAttribute
necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. IndexerName is needed for the indexer to be emitted as Special Member "Chars_get".
To keep indexer an indexer (and not just a parameterized property), compiler also requires DefaultMemberAttribute as well.
LGTM |
1 similar comment
LGTM |
@MattGertz - Update3 bug (copied from VSO). |
|
||
var boundNode = GetBoundForEachStatement(text); | ||
|
||
ForEachEnumeratorInfo info = boundNode.EnumeratorInfoOpt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VSadov It doesn't look like this goes through SemanticModel. Consider adding some tests for SemanticModel APIs.
Allow foreach with string even if string does not implement foreach pattern.
Similarly to arrays and dynamic, we use IEnumerable pattern for binding purposes and then ignore that in emit by using a custom lowering strategy.
Fixes #11387