提交 8abbb194 编写于 作者: R Rikki Gibson

Fix checks for auto-getter where malformed IsReadOnlyAttribute is present

上级 8a28f12b
...@@ -431,10 +431,14 @@ internal override bool IsDeclaredReadOnly ...@@ -431,10 +431,14 @@ internal override bool IsDeclaredReadOnly
return true; return true;
} }
// We can't emit the synthesized attribute for netmodules, so in this case we consider auto-getters **not** implicitly readonly. // If we have IsReadOnly..ctor, we can use the attribute. Otherwise, we need to NOT be a netmodule and the type must not already exist in order to synthesize it.
if (DeclaringCompilation.Options.OutputKind == OutputKind.NetModule && var isReadOnlyAttributeUsable = DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IsReadOnlyAttribute__ctor) != null ||
DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsReadOnlyAttribute).IsErrorType()) (DeclaringCompilation.Options.OutputKind != OutputKind.NetModule &&
DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsReadOnlyAttribute) is MissingMetadataTypeSymbol);
if (!isReadOnlyAttributeUsable)
{ {
// if the readonly attribute isn't usable, don't implicitly make auto-getters readonly.
return false; return false;
} }
......
...@@ -1484,17 +1484,17 @@ public struct S ...@@ -1484,17 +1484,17 @@ public struct S
public int P1 { get; private set; } public int P1 { get; private set; }
} }
"; ";
var moduleComp = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45); var moduleMetadata = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45).EmitToImageReference();
moduleComp.VerifyDiagnostics( var moduleComp = CreateCompilation("", new[] { moduleMetadata });
// (12,21): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsReadOnlyAttribute..ctor' var moduleGetterAttributes = moduleComp.GetMember<PropertySymbol>("S.P1").GetMethod.GetAttributes();
// public int P1 { get; private set; } Assert.Equal(1, moduleGetterAttributes.Length);
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "get").WithArguments("System.Runtime.CompilerServices.IsReadOnlyAttribute", ".ctor").WithLocation(12, 21)); Assert.Equal("CompilerGeneratedAttribute", moduleGetterAttributes[0].AttributeClass.Name);
var dllComp = CreateCompilation(csharp, options: TestOptions.DebugDll, targetFramework: TargetFramework.Mscorlib45); var dllMetadata = CreateCompilation(csharp, options: TestOptions.DebugDll, targetFramework: TargetFramework.Mscorlib45).EmitToImageReference();
dllComp.VerifyDiagnostics( var dllComp = CreateCompilation("", new[] { dllMetadata });
// (12,21): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsReadOnlyAttribute..ctor' var dllGetterAttributes = dllComp.GetMember<PropertySymbol>("S.P1").GetMethod.GetAttributes();
// public int P1 { get; private set; } Assert.Equal(1, dllGetterAttributes.Length);
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "get").WithArguments("System.Runtime.CompilerServices.IsReadOnlyAttribute", ".ctor").WithLocation(12, 21)); Assert.Equal("CompilerGeneratedAttribute", dllGetterAttributes[0].AttributeClass.Name);
} }
[Fact] [Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册