Skip to content
Draft
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;

namespace Mono.Linker.Tests.Cases.DataFlow
{
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
class UnusedVirtualMethodAnnotations
{
[UnconditionalSuppressMessage("Test", "IL2026")]
public static void Main()
{
_ = typeof(TypeOnlyImplementation);

IUsed used = new UsedImplementation();
used.Method(typeof(object));

IPartiallyUsed partiallyUsed = new PartiallyUsedImplementation();
partiallyUsed.Method(typeof(object));
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
interface IUnused
{
[RequiresUnreferencedCode(nameof(Method))]
void Method([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type);
}

class UnusedImplementation : IUnused
{
[ExpectedWarning("IL2046", Tool.Analyzer, "Analyzer does not track reachability")]
[ExpectedWarning("IL2092", Tool.Analyzer, "Analyzer does not track reachability")]
public void Method(Type type) { }
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
interface ITypeOnly
{
[RequiresUnreferencedCode(nameof(Method))]
void Method([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type);
}

class TypeOnlyImplementation : ITypeOnly
{
[ExpectedWarning("IL2046", Tool.Analyzer, "Analyzer does not track reachability")]
[ExpectedWarning("IL2092", Tool.Analyzer, "Analyzer does not track reachability")]
public void Method(Type type) { }
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
interface IUsed
{
[RequiresUnreferencedCode(nameof(Method))]
void Method([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type);
}

class UsedImplementation : IUsed
{
[ExpectedWarning("IL2046")]
[ExpectedWarning("IL2092")]
public void Method(Type type) { }
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do the interfaces need DAM to repro this issue? I would leave this out (or at least add a simpler test without DAM on the interface).

interface IPartiallyUsed
{
[RequiresUnreferencedCode(nameof(Method))]
void Method([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type);
}

class PartiallyUsedImplementation : IPartiallyUsed
{
[ExpectedWarning("IL2046")]
[ExpectedWarning("IL2092")]
public void Method(Type type) { }
}

class UnusedImplementationOfPartiallyUsedInterface : IPartiallyUsed
{
[ExpectedWarning("IL2046", Tool.Analyzer, "Analyzer does not track reachability")]
[ExpectedWarning("IL2092", Tool.Analyzer, "Analyzer does not track reachability")]
public void Method(Type type) { }
Comment thread
jtschuster marked this conversation as resolved.
}
}
}
Loading