diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 73f912f5b7d23..f12568ed2c313 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -11604,7 +11604,6 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. CreateCompilation(source, options: TestOptions.UnsafeDebugDll).VerifyEmitDiagnostics( // (3,16): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context // public A(B[]>.E e) { } @@ -11616,7 +11615,14 @@ unsafe class C { } public void Attribute_TypedDefault_Enum_Implicit_ConstructorArgument_WithUnsafeContext([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine((int)arg.Value == 0); + + class A : Attribute { public unsafe A(B[]>.E e) { } } @@ -11630,8 +11636,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -11673,7 +11678,14 @@ class C { } public void Attribute_GenericTypedDefault_Enum_Implicit_ConstructorArgument([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType.GetGenericTypeDefinition() == typeof(A<>)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine((int)arg.Value == 0); + + class A : Attribute { public A(T t) { } } @@ -11687,8 +11699,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -11730,7 +11741,14 @@ class C { } public void Attribute_TypedDefault_Enum_Explicit_ConstructorArgument([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine((int)arg.Value == 0); + + class A : Attribute { public unsafe A(B[]>.E e) { } } @@ -11744,8 +11762,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -12057,7 +12074,14 @@ unsafe class C { } public void Attribute_GenericTypedConstant_Enum_ConstructorArgument([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType.GetGenericTypeDefinition() == typeof(A<>)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine((int)arg.Value == 33); + + class A : Attribute { public A(T t) { } } @@ -12072,8 +12096,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -12194,7 +12217,14 @@ unsafe class C { } public void Attribute_TypedConstant_Enum_ConstructorArgument([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine((int)arg.Value == 33); + + class A : Attribute { public unsafe A(B[]>.E o) { } } @@ -12209,8 +12239,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -12227,7 +12256,15 @@ unsafe class C { } public void Attribute_TypedConstant_EnumArray_ConstructorArgument([CombinatorialValues("class", "struct")] string kind) { var source = $$""" - class A : System.Attribute + using System; + using System.Collections; + using System.Linq; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine(!((IEnumerable)arg.Value).Cast().Any()); + + class A : Attribute { public unsafe A(B[]>.E[] a) { } } @@ -12241,8 +12278,7 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: static module => + var verifier = CompileAndVerify(source, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? "True" : null, options: TestOptions.UnsafeDebugExe, symbolValidator: static module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); @@ -12261,7 +12297,16 @@ public void Attribute_TypedParamsConstant_EnumArray_ConstructorArgument( [CombinatorialValues("[]{}", "()")] string initializer) { var source = $$""" - class A : System.Attribute + using System; + using System.Collections; + using System.Linq; + using System.Reflection; + + var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); + var arg = attr.ConstructorArguments.Single(); + Console.WriteLine(((IEnumerable)arg.Value).Cast().SingleOrDefault().Value ?? "null"); + + class A : Attribute { public unsafe A(params B[]>.E[] a) { } } @@ -12275,8 +12320,9 @@ public enum E { } unsafe class C { } """; - // https://github.com/dotnet/roslyn/issues/66187 tracks enabling runtime reflection support for this scenario. - var verifier = CompileAndVerify(source, options: TestOptions.UnsafeDebugDll, symbolValidator: module => + var expectedOutput = ExecutionConditionUtil.IsMonoOrCoreClr ? (initializer == "()" ? "0" : "null") : null; + + var verifier = CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.UnsafeDebugExe, symbolValidator: module => { var c = module.GlobalNamespace.GetTypeMember("C"); var attr = c.GetAttributes().Single(d => d.AttributeClass?.Name == "A"); diff --git a/src/Compilers/CSharp/Test/Emit/Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.csproj b/src/Compilers/CSharp/Test/Emit/Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.csproj index 3276fae69d6c0..aa297ca0ff6be 100644 --- a/src/Compilers/CSharp/Test/Emit/Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.csproj +++ b/src/Compilers/CSharp/Test/Emit/Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.csproj @@ -4,7 +4,7 @@ Library Microsoft.CodeAnalysis.CSharp.UnitTests - $(NetRoslyn);net472 + $(NetRoslynNext);net472 true