From 0cdad505918171f513252057b4d56cd73d5a1b55 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 9 May 2022 14:14:20 +0300 Subject: [PATCH 1/4] Fix #61171 --- .../Portable/Binder/Binder_Expressions.cs | 2 +- .../Semantic/Semantics/ColorColorTests.cs | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index aa382d6a986bd..88e27a55adf08 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -6046,7 +6046,7 @@ private BoundExpression BindLeftIdentifierOfPotentialColorColorMemberAccess(Iden { var typeDiagnostics = BindingDiagnosticBag.Create(diagnostics); var boundType = BindNamespaceOrType(left, typeDiagnostics); - if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.ConsiderEverything2)) + if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.AllNullableIgnoreOptions)) { // NOTE: ReplaceTypeOrValueReceiver will call CheckValue explicitly. boundValue = BindToNaturalType(boundValue, valueDiagnostics); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs index 4cb4007004d61..ec8d11f5741a3 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs @@ -2182,5 +2182,57 @@ class C2 Diagnostic(ErrorCode.ERR_MethDelegateMismatch, "new System.Action(C2.ReferenceEquals)").WithArguments("ReferenceEquals", "System.Action").WithLocation(9, 13) ); } + + [WorkItem(61171, "https://github.com/dotnet/roslyn/issues/61171")] + [Theory] + [InlineData(null)] + [InlineData("class")] + [InlineData("struct")] + [InlineData("unmanaged")] + [InlineData("notnull")] + public void WorkItem61171(string constraint) + { + string constraintLine = $"where TValue : {constraint}"; + if (string.IsNullOrEmpty(constraint)) + { + constraintLine = ""; + } + + string source = $@" +#nullable enable + +namespace DataStructures.Trees; + +public sealed class Tree + {constraintLine} +{{ + public abstract class Node + {{ + public abstract NodeType NodeType {{ get; }} + }} + + public sealed class ParentNode : Node + {{ + public override NodeType NodeType => Tree.NodeType.Parent; + }} + + public sealed class LeafNode : Node + {{ + public override Tree.NodeType NodeType => NodeType.Leaf; + }} + + public enum NodeType + {{ + Parent, + Leaf, + }} +}} +"; + + var compilation = CreateCompilation(source); + + compilation.VerifyDiagnostics(); + compilation.VerifyEmitDiagnostics(); + } } } From 81b7d150b4b35200e2a5671deaa1e6ed9e220144 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 May 2022 11:15:11 +0300 Subject: [PATCH 2/4] Change to AllIgnoreOptions --- .../Portable/Binder/Binder_Expressions.cs | 2 +- .../Semantic/Semantics/ColorColorTests.cs | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 88e27a55adf08..eca9f3309e292 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -6046,7 +6046,7 @@ private BoundExpression BindLeftIdentifierOfPotentialColorColorMemberAccess(Iden { var typeDiagnostics = BindingDiagnosticBag.Create(diagnostics); var boundType = BindNamespaceOrType(left, typeDiagnostics); - if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.AllNullableIgnoreOptions)) + if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.AllIgnoreOptions)) { // NOTE: ReplaceTypeOrValueReceiver will call CheckValue explicitly. boundValue = BindToNaturalType(boundValue, valueDiagnostics); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs index ec8d11f5741a3..abcb527ed8804 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs @@ -2190,7 +2190,7 @@ class C2 [InlineData("struct")] [InlineData("unmanaged")] [InlineData("notnull")] - public void WorkItem61171(string constraint) + public void WorkItem61171_Constraints(string constraint) { string constraintLine = $"where TValue : {constraint}"; if (string.IsNullOrEmpty(constraint)) @@ -2232,7 +2232,40 @@ public enum NodeType var compilation = CreateCompilation(source); compilation.VerifyDiagnostics(); - compilation.VerifyEmitDiagnostics(); + } + + [WorkItem(61171, "https://github.com/dotnet/roslyn/issues/61171")] + [Theory] + [InlineData("dynamic", "object")] + [InlineData("(int a, int b)", "(int, int)")] + public void WorkItem61171_DynamicObjectTuple(string inheritedArgument, string propertyArgument) + { + string source = $@" +public class Tree +{{ + public enum NodeType + {{ + Parent, + Leaf, + }} +}} + +public class Tree1 : Tree<{inheritedArgument}> +{{ +}} + +public class Tree2 : Tree1 +{{ + public sealed class LeafNode + {{ + public Tree<{propertyArgument}>.NodeType NodeType => NodeType.Leaf; + }} +}} +"; + + var compilation = CreateCompilation(source); + + compilation.VerifyDiagnostics(); } } } From 3566a822f3b716b7b5f337c4ac7dc0e560999384 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 11 May 2022 18:41:03 +0300 Subject: [PATCH 3/4] Add IL test with modopt(object) --- .../Semantic/Semantics/ColorColorTests.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs index abcb527ed8804..8eb8e1639f675 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs @@ -2267,5 +2267,74 @@ public sealed class LeafNode compilation.VerifyDiagnostics(); } + + [WorkItem(61171, "https://github.com/dotnet/roslyn/issues/61171")] + [Fact] + public void WorkItem61171_ModoptObject() + { + string genericTreeDefinitionSource = @" +public class Tree2 : Tree1 +{ + public sealed class LeafNode + { + public Tree.NodeType NodeType => NodeType.Leaf; + } +} +"; + + string implementingTreeWithModoptObjectILSource = @" +.class public auto ansi beforefieldinit Tree`1 + extends [mscorlib]System.Object +{ + // Nested Types + .class nested public auto ansi sealed NodeType + extends [mscorlib]System.Enum + { + // Fields + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Tree`1/NodeType Parent = int32(0) + .field public static literal valuetype Tree`1/NodeType Leaf = int32(1) + + } // end of class NodeType + + + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2050 + // Code size 7 (0x7) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method Tree`1::.ctor + +} // end of class Tree`1 + +.class public auto ansi beforefieldinit Tree1 + extends class Tree`1 +{ + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2058 + // Code size 7 (0x7) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void class Tree`1::.ctor() + IL_0006: ret + } // end of method Tree1::.ctor + +} // end of class Tree1 +"; + + var compilation = CreateCompilationWithIL(genericTreeDefinitionSource, implementingTreeWithModoptObjectILSource); + + compilation.VerifyDiagnostics(); + } } } From 8b3fe4b65d1abb68a31c70d64d24819b7c41f589 Mon Sep 17 00:00:00 2001 From: AlFas Date: Thu, 12 May 2022 23:18:36 +0300 Subject: [PATCH 4/4] Reduce testing IL size Co-authored-by: Fred Silberberg --- .../Semantic/Semantics/ColorColorTests.cs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs index 8eb8e1639f675..2493a9866c4cb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs @@ -2302,13 +2302,9 @@ .field public specialname rtspecialname int32 value__ .method public hidebysig specialname rtspecialname instance void .ctor () cil managed { - // Method begins at RVA 0x2050 - // Code size 7 (0x7) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ret + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret } // end of method Tree`1::.ctor } // end of class Tree`1 @@ -2320,13 +2316,9 @@ .class public auto ansi beforefieldinit Tree1 .method public hidebysig specialname rtspecialname instance void .ctor () cil managed { - // Method begins at RVA 0x2058 - // Code size 7 (0x7) - .maxstack 8 - - IL_0000: ldarg.0 - IL_0001: call instance void class Tree`1::.ctor() - IL_0006: ret + ldarg.0 + call instance void class Tree`1::.ctor() + ret } // end of method Tree1::.ctor } // end of class Tree1