From c300c8c54a8964bc1c7a8dae0810045d07035998 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Wed, 17 Apr 2019 17:21:02 -0700 Subject: [PATCH 1/3] Add new ConversionKind to IsImplicitConversion test --- .../Binder/Semantics/Conversions/ConversionKindExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs index a6b1b2fdee657..b2361704f9255 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs @@ -21,6 +21,7 @@ public static bool IsImplicitConversion(this ConversionKind conversionKind) switch (conversionKind) { case ConversionKind.NoConversion: + case ConversionKind.UnsetConversionKind: return false; case ConversionKind.Identity: From 23733a225a0af7c3d5cc48a1ccd18c798e97dc6f Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Fri, 19 Apr 2019 15:53:16 -0700 Subject: [PATCH 2/3] Add test for IsImplicit --- .../Compilation/GetSemanticInfoTests.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs index 432570f0e21a6..6956ee49be779 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs @@ -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() + { + 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(); + var foreachSyntaxNode = root.DescendantNodes().OfType().Single(); + var foreachSymbolInfo = model.GetForEachStatementInfo(foreachSyntaxNode); + + Assert.Equal(Conversion.UnsetConversion, foreachSymbolInfo.CurrentConversion); + Assert.True(foreachSymbolInfo.CurrentConversion.Exists); + Assert.False(foreachSymbolInfo.CurrentConversion.IsImplicit); + } } } From e8494860e53478ed077c1d0b92ce46db90ca4b1d Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Thu, 23 May 2019 12:19:33 -0700 Subject: [PATCH 3/3] Test cleanup based on PR feedback --- .../CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs index 5d92c5076e4c9..cab91a5908b77 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs @@ -5919,7 +5919,7 @@ public void GetSpecialType_ThrowsOnGreaterThanCount() [Fact] [WorkItem(34984, "https://github.com/dotnet/roslyn/issues/34984")] - public async Task ConversionIsExplicit_UnsetConversionKind() + public void ConversionIsExplicit_UnsetConversionKind() { var source = @"class C1 @@ -5928,7 +5928,7 @@ public async Task ConversionIsExplicit_UnsetConversionKind() class C2 { - public void Foo() + public void M() { var c = new C1(); foreach (string item in c.Items) @@ -5939,7 +5939,7 @@ public void Foo() var tree = comp.SyntaxTrees.Single(); var model = comp.GetSemanticModel(tree); - var root = await tree.GetRootAsync(); + var root = tree.GetRoot(); var foreachSyntaxNode = root.DescendantNodes().OfType().Single(); var foreachSymbolInfo = model.GetForEachStatementInfo(foreachSyntaxNode);