Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter RequiresLocationAttribute from ref readonly parameters #68870

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member Author

@jjonescz jjonescz Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it means the presence of the attribute cannot be verified using compiler APIs anymore, I think. But it's still verified in the sense that it makes PEParameterSymbol.RefKind to be decoded correctly as RefReadonlyParameter if the attribute is present.

}

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