Skip to content

Commit a718cbe

Browse files
authored
Add test for invalid trim annotations in top-level method (#103182)
Adds a testcase for #101215.
1 parent 2038cb5 commit a718cbe

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TopLevelStatementsTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ public Task BasicDataFlow ()
1313
{
1414
return RunTest ();
1515
}
16+
17+
[Fact]
18+
public Task InvalidAnnotations ()
19+
{
20+
return RunTest ();
21+
}
1622
}
1723
}

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ static void RequirePublicFields (
338338
{
339339
}
340340

341-
[ExpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
341+
[UnexpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
342342
static void TestFlowOutOfField ()
343343
{
344344
RequirePublicFields (unsupportedTypeInstance);
345345
}
346346

347-
[ExpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
347+
[UnexpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
348348
public static void Test () {
349349
var t = GetUnsupportedTypeInstance ();
350350
unsupportedTypeInstance = t;

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class UnsupportedType ()
244244
static UnsupportedType GetUnsupportedTypeInstance () => null;
245245

246246
[ExpectedWarning ("IL2098", nameof (UnsupportedType))]
247-
[ExpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
247+
[UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
248248
static void RequirePublicMethods (
249249
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
250250
UnsupportedType unsupportedTypeInstance)
@@ -259,7 +259,7 @@ static void RequirePublicFields (
259259
{
260260
}
261261

262-
[ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
262+
[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
263263
public static void Test () {
264264
var t = GetUnsupportedTypeInstance ();
265265
RequirePublicMethods (t);

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static void TestMethodReturnValue () {
220220
RequirePublicFields (t);
221221
}
222222

223-
[ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
223+
[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
224224
static void TestCtorReturnValue () {
225225
var t = new UnsupportedType ();
226226
RequirePublicFields (t);

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void RequirePublicFields (
122122
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
123123
UnsupportedType unsupportedTypeInstance) { }
124124

125-
[ExpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
125+
[UnexpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
126126
static void TestMethodThisParameter () {
127127
var t = GetUnsupportedTypeInstance ();
128128
t.GetMethod ("foo");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Project Sdk="Microsoft.NET.Sdk" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using Mono.Linker.Tests.Cases.Expectations.Assertions;
6+
7+
[assembly: ExpectedNoWarnings]
8+
9+
Test ();
10+
11+
[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")]
12+
[Kept]
13+
static void Test () {
14+
RequireAll (GetUnsupportedType ());
15+
}
16+
17+
[ExpectedWarning ("IL2098", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/101215")]
18+
[Kept]
19+
static void RequireAll(
20+
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
21+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] UnsupportedType f) {}
22+
23+
[Kept]
24+
static UnsupportedType GetUnsupportedType () => new UnsupportedType ();
25+
26+
[Kept]
27+
[KeptMember (".ctor()")]
28+
class UnsupportedType {}

0 commit comments

Comments
 (0)