提交 ba9e1121 编写于 作者: R Rikki Gibson

Fixes from feedback

上级 654ff743
...@@ -422,13 +422,24 @@ internal Accessibility LocalAccessibility ...@@ -422,13 +422,24 @@ internal Accessibility LocalAccessibility
/// <summary> /// <summary>
/// Indicates whether this accessor is readonly due to reasons scoped to itself and its containing property. /// Indicates whether this accessor is readonly due to reasons scoped to itself and its containing property.
/// </summary> /// </summary>
internal override bool IsDeclaredReadOnly => LocalDeclaredReadOnly || _property.HasReadOnlyModifier || IsReadOnlyAutoGetter; internal override bool IsDeclaredReadOnly
{
get
{
return LocalDeclaredReadOnly || _property.HasReadOnlyModifier || isReadOnlyAutoGetter();
private bool IsReadOnlyAutoGetter => ContainingType.IsStructType() && !_property.IsStatic && _isAutoPropertyAccessor && MethodKind == MethodKind.PropertyGet && !IsBadNetModule; bool isReadOnlyAutoGetter() =>
ContainingType.IsStructType() &&
!_property.IsStatic &&
_isAutoPropertyAccessor &&
MethodKind == MethodKind.PropertyGet &&
!isBadNetModule();
// We can't emit the synthesized attribute for netmodules, so in this case we consider auto-getters **not** implicitly readonly. // We can't emit the synthesized attribute for netmodules, so in this case we consider auto-getters **not** implicitly readonly.
private bool IsBadNetModule => DeclaringCompilation.Options.OutputKind == OutputKind.NetModule && bool isBadNetModule() => DeclaringCompilation.Options.OutputKind == OutputKind.NetModule &&
DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsReadOnlyAttribute) is MissingMetadataTypeSymbol; DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsReadOnlyAttribute) is MissingMetadataTypeSymbol;
}
}
private DeclarationModifiers MakeModifiers(AccessorDeclarationSyntax syntax, bool isExplicitInterfaceImplementation, private DeclarationModifiers MakeModifiers(AccessorDeclarationSyntax syntax, bool isExplicitInterfaceImplementation,
bool hasBody, Location location, DiagnosticBag diagnostics, out bool modifierErrors) bool hasBody, Location location, DiagnosticBag diagnostics, out bool modifierErrors)
......
...@@ -1453,8 +1453,18 @@ public struct S ...@@ -1453,8 +1453,18 @@ public struct S
public int P1 { get; private set; } public int P1 { get; private set; }
} }
"; ";
var comp = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45); var moduleMetadata = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45).EmitToImageReference();
comp.VerifyDiagnostics(); var moduleComp = CreateCompilation("", new[] { moduleMetadata });
var moduleGetterAttributes = moduleComp.GetMember<PropertySymbol>("S.P1").GetMethod.GetAttributes();
Assert.Equal(1, moduleGetterAttributes.Length);
Assert.Equal("CompilerGeneratedAttribute", moduleGetterAttributes[0].AttributeClass.Name);
var dllMetadata = CreateCompilation(csharp, options: TestOptions.DebugDll, targetFramework: TargetFramework.Mscorlib45).EmitToImageReference();
var dllComp = CreateCompilation("", new[] { dllMetadata });
var dllGetterAttributes = dllComp.GetMember<PropertySymbol>("S.P1").GetMethod.GetAttributes();
Assert.Equal(2, dllGetterAttributes.Length);
Assert.Equal("IsReadOnlyAttribute", dllGetterAttributes[0].AttributeClass.Name);
Assert.Equal("CompilerGeneratedAttribute", dllGetterAttributes[1].AttributeClass.Name);
} }
[Fact] [Fact]
...@@ -1466,11 +1476,14 @@ public struct S ...@@ -1466,11 +1476,14 @@ public struct S
public int P1 { readonly get; private set; } public int P1 { readonly get; private set; }
} }
"; ";
var comp = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45); var moduleComp = CreateCompilation(csharp, options: TestOptions.DebugModule, targetFramework: TargetFramework.Mscorlib45);
comp.VerifyDiagnostics( moduleComp.VerifyDiagnostics(
// (4,30): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' is not defined or imported // (4,30): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' is not defined or imported
// public int P1 { readonly get; private set; } // public int P1 { readonly get; private set; }
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "get").WithArguments("System.Runtime.CompilerServices.IsReadOnlyAttribute").WithLocation(4, 30)); Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "get").WithArguments("System.Runtime.CompilerServices.IsReadOnlyAttribute").WithLocation(4, 30));
var dllComp = CreateCompilation(csharp, options: TestOptions.DebugDll, targetFramework: TargetFramework.Mscorlib45);
dllComp.VerifyDiagnostics();
} }
[Fact] [Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册