提交 a09ea02b 编写于 作者: J Julien Couvreur

Fix for #7840: add missing check for DynamicAttribute type

上级 9927226d
......@@ -2879,6 +2879,17 @@ internal bool HasDynamicEmitAttributes()
(object)GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_DynamicAttribute__ctorTransformFlags) != null;
}
/// <summary>
/// Returns whether the compilation has the Boolean type and if it's good.
/// </summary>
/// <returns>Returns true if Boolean is present and healthy.</returns>
internal bool CanEmitBoolean()
{
var boolType = GetSpecialType(SpecialType.System_Boolean);
var diagnostic = boolType.GetUseSiteDiagnostic();
return (diagnostic == null) || (diagnostic.Severity != DiagnosticSeverity.Error);
}
internal override AnalyzerDriver AnalyzerForLanguage(ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerManager analyzerManager)
{
Func<SyntaxNode, SyntaxKind> getKind = node => node.Kind();
......
......@@ -45,14 +45,11 @@ internal override void AddSynthesizedAttributes(ModuleCompilationState compilati
CSharpCompilation compilation = this.DeclaringCompilation;
// Assume that someone checked earlier that the attribute ctor is available and has no use-site errors.
AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor));
// TODO (tomat): do we need to emit dynamic attribute on any synthesized field?
if (this.Type.ContainsDynamic())
if (this.Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean())
{
// Assume that someone checked earlier that the attribute ctor is available and has no use-site errors.
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, customModifiersCount: 0));
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length));
}
}
......
......@@ -81,9 +81,9 @@ internal override void AddSynthesizedAttributes(ModuleCompilationState compilati
{
base.AddSynthesizedAttributes(compilationState, ref attributes);
if (this.ReturnType.ContainsDynamic())
var compilation = this.DeclaringCompilation;
if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean())
{
var compilation = this.DeclaringCompilation;
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length));
}
}
......
......@@ -159,14 +159,9 @@ 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())
if (Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean())
{
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));
}
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册