Skip to content

Commit

Permalink
Filter RequiresLocationAttribute from ref readonly parameters (#6…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Jul 7, 2023
1 parent 282bcb4 commit e3ed9a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
}

bool filterIsReadOnlyAttribute = this.RefKind == RefKind.In;
bool filterRequiresLocationAttribute = this.RefKind == RefKind.RefReadOnlyParameter;

CustomAttributeHandle paramArrayAttribute;
CustomAttributeHandle constantAttribute;
Expand All @@ -1057,9 +1058,9 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
out _,
filterIsReadOnlyAttribute ? AttributeDescription.IsReadOnlyAttribute : default,
out _,
AttributeDescription.ScopedRefAttribute,
filterRequiresLocationAttribute ? AttributeDescription.RequiresLocationAttribute : default,
out _,
default,
AttributeDescription.ScopedRefAttribute,
out _,
default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,7 @@ private static void VerifyRefReadonlyParameter(ParameterSymbol parameter,

if (attributes)
{
if (parameter.ContainingModule is SourceModuleSymbol)
{
Assert.Empty(parameter.GetAttributes());
}
else
{
var attribute = Assert.Single(parameter.GetAttributes());
Assert.Equal("System.Runtime.CompilerServices.RequiresLocationAttribute", attribute.AttributeClass.ToTestDisplayString());
Assert.Empty(attribute.ConstructorArguments);
Assert.Empty(attribute.NamedArguments);
}
Assert.Empty(parameter.GetAttributes());
}

if (modreq)
Expand Down Expand Up @@ -129,11 +119,6 @@ static void verify(ModuleSymbol m)

var p = m.GlobalNamespace.GetMember<MethodSymbol>("C.M").Parameters.Single();
VerifyRefReadonlyParameter(p);

if (m is not SourceModuleSymbol)
{
Assert.Same(attribute, p.GetAttributes().Single().AttributeClass);
}
}
}

Expand Down Expand Up @@ -183,17 +168,10 @@ .maxstack 8

var p = comp.GlobalNamespace.GetMember<MethodSymbol>("C.M").Parameters.Single();
VerifyRefReadonlyParameter(p, attributes: false);
var attributes = p.GetAttributes();
Assert.Equal(new[]
{
"System.Runtime.CompilerServices.IsReadOnlyAttribute",
"System.Runtime.CompilerServices.RequiresLocationAttribute"
}, attributes.Select(a => a.AttributeClass.ToTestDisplayString()));
Assert.All(attributes, a =>
{
Assert.Empty(a.ConstructorArguments);
Assert.Empty(a.NamedArguments);
});
var attribute = Assert.Single(p.GetAttributes());
Assert.Equal("System.Runtime.CompilerServices.IsReadOnlyAttribute", attribute.AttributeClass.ToTestDisplayString());
Assert.Empty(attribute.ConstructorArguments);
Assert.Empty(attribute.NamedArguments);
}

[Fact]
Expand Down Expand Up @@ -543,9 +521,8 @@ static void verify(ModuleSymbol m)
var p = m.GlobalNamespace.GetMember<MethodSymbol>("C.M").Parameters.Single();
var ptr = (FunctionPointerTypeSymbol)p.Type;
var p2 = ptr.Signature.Parameters.Single();
VerifyRefReadonlyParameter(p2, refKind: m is SourceModuleSymbol, modreq: true, attributes: false);
VerifyRefReadonlyParameter(p2, refKind: m is SourceModuleSymbol, modreq: true);
Assert.Equal(m is SourceModuleSymbol ? RefKind.RefReadOnlyParameter : RefKind.In, p2.RefKind);
Assert.Empty(p2.GetAttributes());
}
}

Expand Down

0 comments on commit e3ed9a4

Please sign in to comment.