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

Add CompilerGeneratedAttribute to record members #58542

Merged
merged 13 commits into from
Feb 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public StringBuilder Append(string s)

";
var comp = CreateEmptyCompilation(source);
CompileAndVerify(comp, symbolValidator: validate);
CompileAndVerify(comp, symbolValidator: validate, verify: Verification.Skipped);
Copy link
Member

Choose a reason for hiding this comment

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

What was the verification error that was skipped here?

Copy link
Member Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

Instead of using an empty compilation, I'd recommend using CreateCompilation then MakeTypeMissing. Then I don't think we'll need to skip PE verification

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that type of PE verification failure is generally a real failure. It makes me worried that we missed a case and are attempting to emit a reference to the attribute when it doesn't exist. Think @jcouv approach is correct here to use MakeTypeMissing that will help rule out that problem.

Copy link
Member

Choose a reason for hiding this comment

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

This worked:


        [Fact]
        [WorkItem(46439, "https://github.com/dotnet/roslyn/issues/46439")]
        public void AttributeIsMissing()
        {
            string source = @"
record struct R;
";
            var comp = CreateCompilation(source);
            comp.MakeTypeMissing(WellKnownType.System_Runtime_CompilerServices_CompilerGeneratedAttribute);
            var verifier = CompileAndVerify(comp, symbolValidator: validate);
            verifier.VerifyDiagnostics();

            void validate(ModuleSymbol module)
            {
                var record = module.GlobalNamespace.GetTypeMember("R");
                Assert.Equal(7, record.GetMembers().Length); // If a new record member is added, extend the test with its behavior regarding CompilerGeneratedAttribute.

                var ctor = record.GetMember(WellKnownMemberNames.InstanceConstructorName);
                Assert.Empty(ctor.GetAttributes());

                var toString = record.GetMember(WellKnownMemberNames.ObjectToString);
                Assert.Empty(toString.GetAttributes());

                var op_Equality = record.GetMember(WellKnownMemberNames.EqualityOperatorName);
                Assert.Empty(op_Equality.GetAttributes());

                var op_Inequality = record.GetMember(WellKnownMemberNames.InequalityOperatorName);
                Assert.Empty(op_Inequality.GetAttributes());

                var getHashCode = record.GetMember(WellKnownMemberNames.ObjectGetHashCode);
                Assert.Empty(getHashCode.GetAttributes());

                var equals = record.GetMembers(WellKnownMemberNames.ObjectEquals);
                Assert.Equal(2, equals.Length);
                Assert.Empty(equals[0].GetAttributes());
                Assert.Empty(equals[1].GetAttributes());
            }
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! I didn't know MakeTypeMissing is a thing!


void validate(ModuleSymbol module)
{
Expand Down