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

Explicit conversion in foreach is incorrect #35918

Open
ryzngard opened this issue May 23, 2019 · 0 comments
Open

Explicit conversion in foreach is incorrect #35918

ryzngard opened this issue May 23, 2019 · 0 comments
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@ryzngard
Copy link
Contributor

ryzngard commented May 23, 2019

See #35095 (comment) for context

For an explicit conversion from foreach, the expected value should be NoConversion when the current type is explicit and the enumerable type is unknown

[@gafter added]
The context is a test with the source code

class C1
{
}

class C2
{
    public void M() 
    {
        var c = new C1();
        foreach (string item in c.Items)
        {
        }
}

which tests

            var comp = CreateCompilation(source);
            var tree = comp.SyntaxTrees.Single();
            var model = comp.GetSemanticModel(tree);

            var root = tree.GetRoot();
            var foreachSyntaxNode = root.DescendantNodes().OfType<ForEachStatementSyntax>().Single();
            var foreachSymbolInfo = model.GetForEachStatementInfo(foreachSyntaxNode);

            Assert.Equal(Conversion.UnsetConversion, foreachSymbolInfo.CurrentConversion);
            Assert.True(foreachSymbolInfo.CurrentConversion.Exists);
            Assert.False(foreachSymbolInfo.CurrentConversion.IsImplicit);

and the comment was

I'd expect the conversion to be Conversion.NoConversion (and Exists to be false).

I think that was changed by PR #33648 which introduced UnsetConversion, but not intentionally.

@gafter gafter added this to the Backlog milestone Jul 9, 2019
@gafter gafter added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

No branches or pull requests

2 participants