Skip to content

Commit

Permalink
Add test for invalid trim annotations in top-level method (#103182)
Browse files Browse the repository at this point in the history
Adds a testcase for #101215.
  • Loading branch information
sbomer authored Jun 12, 2024
1 parent 2038cb5 commit a718cbe
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public Task BasicDataFlow ()
{
return RunTest ();
}

[Fact]
public Task InvalidAnnotations ()
{
return RunTest ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ static void RequirePublicFields (
{
}

[ExpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
static void TestFlowOutOfField ()
{
RequirePublicFields (unsupportedTypeInstance);
}

[ExpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
public static void Test () {
var t = GetUnsupportedTypeInstance ();
unsupportedTypeInstance = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class UnsupportedType ()
static UnsupportedType GetUnsupportedTypeInstance () => null;

[ExpectedWarning ("IL2098", nameof (UnsupportedType))]
[ExpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
static void RequirePublicMethods (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
UnsupportedType unsupportedTypeInstance)
Expand All @@ -259,7 +259,7 @@ static void RequirePublicFields (
{
}

[ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
public static void Test () {
var t = GetUnsupportedTypeInstance ();
RequirePublicMethods (t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static void TestMethodReturnValue () {
RequirePublicFields (t);
}

[ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
static void TestCtorReturnValue () {
var t = new UnsupportedType ();
RequirePublicFields (t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void RequirePublicFields (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
UnsupportedType unsupportedTypeInstance) { }

[ExpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[UnexpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
static void TestMethodThisParameter () {
var t = GetUnsupportedTypeInstance ();
t.GetMethod ("foo");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project Sdk="Microsoft.NET.Sdk" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;

[assembly: ExpectedNoWarnings]

Test ();

[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
[Kept]
static void Test () {
RequireAll (GetUnsupportedType ());
}

[ExpectedWarning ("IL2098", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/101215")]
[Kept]
static void RequireAll(
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] UnsupportedType f) {}

[Kept]
static UnsupportedType GetUnsupportedType () => new UnsupportedType ();

[Kept]
[KeptMember (".ctor()")]
class UnsupportedType {}

0 comments on commit a718cbe

Please sign in to comment.