Skip to content

Commit

Permalink
Add regression test for assembly origin for event marking (#102836)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtschuster authored May 30, 2024
1 parent f36a477 commit 21f356a
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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)
{
}
}
}

0 comments on commit 21f356a

Please sign in to comment.