提交 fbbc5c45 编写于 作者: C Charles Stoner

Merge pull request #7725 from cston/6126

Remove incorrect condition in SynthesizedParameterSymbol.AddSynthesizedAttributes
......@@ -159,11 +159,14 @@ internal override void AddSynthesizedAttributes(ModuleCompilationState compilati
// this is a no-op. Emitting an error here, or when the original parameter was bound, would
// adversely effect the compilation or potentially change overload resolution.
var compilation = this.DeclaringCompilation;
if (Type.ContainsDynamic() &&
compilation.HasDynamicEmitAttributes() &&
compilation.GetSpecialType(SpecialType.System_Boolean).SpecialType == SpecialType.System_Boolean)
if (Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes())
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind));
var boolType = compilation.GetSpecialType(SpecialType.System_Boolean);
var diagnostic = boolType.GetUseSiteDiagnostic();
if ((diagnostic == null) || (diagnostic.Severity != DiagnosticSeverity.Error))
{
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind));
}
}
}
......
......@@ -1189,16 +1189,13 @@ public void DynamicLambdaParameterChecksDynamic()
var source =
@"using System;
public class C
class C
{
public static void Main()
static void Main()
{
Func<dynamic, object> f = x => x;
T(f(null));
Func<dynamic, dynamic[], object> f = (x, y) => x;
f(null, null);
}
public static void T(object o) { }
}";
// Make sure we emit without errors when dynamic attributes are not present.
......@@ -1207,7 +1204,7 @@ public static void Main()
Signature(
"C+<>c",
"<Main>b__0_0",
".method assembly hidebysig instance System.Object <Main>b__0_0(System.Object x) cil managed")
".method assembly hidebysig instance System.Object <Main>b__0_0(System.Object x, System.Object[] y) cil managed")
});
}
......@@ -1218,16 +1215,13 @@ public void DynamicLambdaParametersEmitAsDynamic()
var source =
@"using System;
public class C
class C
{
public static void Main()
static void Main()
{
Func<dynamic, object> f = x => x;
T(f(null));
Func<dynamic, dynamic[], object> f = (x, y) => x;
f(null, null);
}
public static void T(object o) { }
}";
CompileAndVerify(source, additionalRefs: new[] { CSharpRef, SystemCoreRef }, expectedSignatures: new[]
......@@ -1235,8 +1229,40 @@ public static void Main()
Signature(
"C+<>c",
"<Main>b__0_0",
".method assembly hidebysig instance System.Object <Main>b__0_0([System.Runtime.CompilerServices.DynamicAttribute()] System.Object x) cil managed")
".method assembly hidebysig instance System.Object <Main>b__0_0([System.Runtime.CompilerServices.DynamicAttribute()] System.Object x, [System.Runtime.CompilerServices.DynamicAttribute(System.Collections.ObjectModel.ReadOnlyCollection`1[System.Reflection.CustomAttributeTypedArgument])] System.Object[] y) cil managed")
});
}
[Fact]
[WorkItem(6126, "https://github.com/dotnet/roslyn/issues/6126")]
public void DynamicLambdaParametersMissingBoolean()
{
var source0 =
@"namespace System
{
public class Object { }
public class ValueType { }
public struct Void { }
public struct IntPtr { }
public class MulticastDelegate { }
}";
var source1 =
@"delegate void D<T>(T t);
class C
{
static void Main()
{
D<dynamic[]> d = o => { };
d(null);
}
}";
var comp = CreateCompilation(source0);
comp.VerifyDiagnostics();
var ref0 = comp.EmitToImageReference();
comp = CreateCompilation(source1, references: new[] { ref0, SystemCoreRef });
comp.VerifyDiagnostics();
// Make sure we emit without errors when System.Boolean is missing.
CompileAndVerify(comp, verify: false);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册