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

Add new ConversionKind to IsImplicitConversion test #35095

Merged
merged 5 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static bool IsImplicitConversion(this ConversionKind conversionKind)
switch (conversionKind)
{
case ConversionKind.NoConversion:
case ConversionKind.UnsetConversionKind:
return false;

case ConversionKind.Identity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5916,5 +5916,36 @@ public void GetSpecialType_ThrowsOnGreaterThanCount()

Assert.True(exceptionThrown, $"{nameof(comp.GetSpecialType)} did not throw when it should have.");
}

[Fact]
[WorkItem(34984, "https://github.com/dotnet/roslyn/issues/34984")]
public async Task ConversionIsExplicit_UnsetConversionKind()
{
var source =
@"class C1
{
}

class C2
{
public void Foo()
ryzngard marked this conversation as resolved.
Show resolved Hide resolved
{
var c = new C1();
foreach (string item in c.Items)
{
}
}";
var comp = CreateCompilation(source);
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

var root = await tree.GetRootAsync();
ryzngard marked this conversation as resolved.
Show resolved Hide resolved
var foreachSyntaxNode = root.DescendantNodes().OfType<ForEachStatementSyntax>().Single();
var foreachSymbolInfo = model.GetForEachStatementInfo(foreachSyntaxNode);

Assert.Equal(Conversion.UnsetConversion, foreachSymbolInfo.CurrentConversion);
Copy link
Member

@jcouv jcouv Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnsetConversion [](start = 36, length = 15)

Feels like there is a bigger issue here. 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.
Let's discuss with @gafter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to continue with this PR as is to fix the crash. I've filed #35918 to track a deeper fix if needed.

Assert.True(foreachSymbolInfo.CurrentConversion.Exists);
Assert.False(foreachSymbolInfo.CurrentConversion.IsImplicit);
}
}
}