Skip to content
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

Merged
merged 1 commit into from
May 24, 2016

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented May 18, 2016

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

…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
@VSadov VSadov changed the title Allow foreach wiith string even if string does not implement foreach pattern. Allow foreach with string even if string does not implement foreach pattern. May 18, 2016
@balajikris
Copy link
Member

@dotnet-bot retest prtest/win/dbg/unit32 please
// Previous failure: http://dotnet-ci.cloudapp.net/job/roslyn_prtest_win_dbg_unit32/7329/
// Retest reason: infra break

@balajikris
Copy link
Member

@dotnet-bot retest prtest/win/dbg/unit64 please
// Previous failure: http://dotnet-ci.cloudapp.net/job/roslyn_prtest_win_dbg_unit64/7291/
// Retest reason: infra break

@VSadov
Copy link
Member Author

VSadov commented May 22, 2016

@dotnet/roslyn-compiler please review

public int Length => 2;

[System.Runtime.CompilerServices.IndexerName(""Chars"")]
public char this[int i] => 'a';
Copy link
Member

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?

Copy link
Member Author

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.

@cston
Copy link
Member

cston commented May 23, 2016

LGTM

1 similar comment
@jcouv
Copy link
Member

jcouv commented May 23, 2016

LGTM

@VSadov VSadov added this to the 1.3 milestone May 24, 2016
@VSadov
Copy link
Member Author

VSadov commented May 24, 2016

@MattGertz - Update3 bug (copied from VSO).
The PR is from the last week, but was waiting for reviews.

@VSadov VSadov merged commit 42c0eea into dotnet:master May 24, 2016

var boundNode = GetBoundForEachStatement(text);

ForEachEnumeratorInfo info = boundNode.EnumeratorInfoOpt;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants