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

Fix warning suppressions on types for type hierarchy #2148

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,14 +1756,16 @@ protected internal virtual TypeDefinition MarkType (TypeReference reference, Dep

MarkType (type.BaseType, new DependencyInfo (DependencyKind.BaseType, type));

MarkCustomAttributes (type, new DependencyInfo (DependencyKind.CustomAttribute, type));

// The DynamicallyAccessedMembers hiearchy processing must be done after the base type was marked
// (to avoid inconsistencies in the cache), but before anything else as work done below
// (to avoid inconsistencies in the cache), and after marking custom attributes (in case the attributes have
// warning suppressions for the type hierarchy marking) but before anything else as work done below
// might need the results of the processing here.
_dynamicallyAccessedMembersTypeHierarchy.ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy (type);

if (type.DeclaringType != null)
MarkType (type.DeclaringType, new DependencyInfo (DependencyKind.DeclaringType, type));
MarkCustomAttributes (type, new DependencyInfo (DependencyKind.CustomAttribute, type));
MarkSecurityDeclarations (type, new DependencyInfo (DependencyKind.CustomAttribute, type));

if (type.IsMulticastDelegate ()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupLinkerArgument ("-a", "test.exe", "library")]
[ExpectedNoWarnings]
[KeptMember (".ctor()")]
public class TypeHierarchyLibraryModeSuppressions
LakshanF marked this conversation as resolved.
Show resolved Hide resolved
{
public static void Main ()
{
var t1 = typeof (Unsuppressed);
var t2 = typeof (Suppressed);
}

[Kept]
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
[ExpectedWarning ("IL2026", nameof (Unsuppressed))]
class Unsuppressed
{
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("--RUC on Unsuppressed--")]
public void RUCMethod () { }
}

[Kept]
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
[UnconditionalSuppressMessage ("TrimAnalysis", "IL2026")]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
class Suppressed
{
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("--RUC on Suppressed--")]
public void RUCMethod () { }
}
}
}