From 21f356a4f955bcff66f84762be4826ba605a3645 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Thu, 30 May 2024 07:49:55 -0700 Subject: [PATCH] Add regression test for assembly origin for event marking (#102836) Adds a regression test for the issue that was fixed in #102613. The assembly level attribute marks the members on the referenced type, and the assembly is the MessageOrigin for the marking. I confirmed this fails with before #102613. --- .../AssemblyAttributeAccessesMembers.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeAccessesMembers.cs diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeAccessesMembers.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeAccessesMembers.cs new file mode 100644 index 0000000000000..5d1ebb39cfb18 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeAccessesMembers.cs @@ -0,0 +1,66 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Mono.Linker.Tests.Cases.Attributes; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +[assembly: KeptAttributeAttribute (typeof (AccessesMembersAttribute))] +[assembly: AccessesMembers (typeof (AssemblyAttributeAccessesMembers.TypeWithMembers))] +namespace Mono.Linker.Tests.Cases.Attributes +{ + /// + /// A regression test for the issue that was fixed by https://github.com/dotnet/runtime/pull/102613. + /// Events were assumed to always have a MemberDefinition or Descriptor file as the warning origin, but it also can occur from an assembly attribute. + /// + [Kept] + class AssemblyAttributeAccessesMembers + { + [Kept] + public static void Main () + { + typeof (AssemblyAttributeAccessesMembers).Assembly.GetCustomAttributes (false); + } + + [Kept] + public class TypeWithMembers + { + [Kept] + public TypeWithMembers () { } + + [Kept] + public void Method () { } + + [Kept] + public int Field; + + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + + [Kept] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptBackingField] + public event EventHandler Event; + } + } + + [Kept] + [KeptBaseType (typeof (Attribute))] + public class AccessesMembersAttribute : Attribute + { + [Kept] + public AccessesMembersAttribute ( + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] + Type type) + { + } + } +}