From 7d5955a8e80ee516a2ae99932b8cb68c3071f0c6 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 31 Dec 2021 18:13:01 +0200 Subject: [PATCH] Add CompilerGeneratedAttribute to record members --- .../Records/SynthesizedRecordEqualityOperatorBase.cs | 11 +++++++++++ .../Records/SynthesizedRecordOrdinaryMethod.cs | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs index a85df5e9f7b81..e3f3d3ce862d2 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs @@ -6,7 +6,9 @@ using System.Diagnostics; using System.Globalization; using System.Threading; +using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols @@ -73,5 +75,14 @@ protected sealed override (TypeWithAnnotations ReturnType, ImmutableArray 2; + + internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder attributes) + { + base.AddSynthesizedAttributes(moduleBuilder, ref attributes); + Debug.Assert(IsImplicitlyDeclared); + var compilation = this.DeclaringCompilation; + AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + Debug.Assert(WellKnownMembers.IsSynthesizedAttributeOptional(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index ec7928198b68e..99e854649fd35 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -3,9 +3,12 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; +using System.Diagnostics; using System.Globalization; using System.Threading; +using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols @@ -60,6 +63,15 @@ protected sealed override void CheckConstraintsForExplicitInterfaceType(Conversi { } + internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder attributes) + { + base.AddSynthesizedAttributes(moduleBuilder, ref attributes); + Debug.Assert(IsImplicitlyDeclared); + var compilation = this.DeclaringCompilation; + AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + Debug.Assert(WellKnownMembers.IsSynthesizedAttributeOptional(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + } + protected sealed override SourceMemberMethodSymbol? BoundAttributesSource => null; internal sealed override OneOrMany> GetAttributeDeclarations() => OneOrMany.Create(default(SyntaxList));