-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't emit analyzer warnings for MakeGeneric understood by ILC (#100858)
Follow up to #99037. Resolves #81204. When `MakeGenericXXX` API is used in the "bridging constraints" pattern and all types/members involved are statically known, don't emit warning from the Roslyn analyzer since ILC will do the right thing and ensure this works.
- Loading branch information
1 parent
324bd56
commit 7b534da
Showing
7 changed files
with
316 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataflowIntrinsics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
|
||
namespace Mono.Linker.Tests.Cases.DataFlow | ||
{ | ||
[SkipKeptItemsValidation] | ||
[ExpectedNoWarnings] | ||
class MakeGenericDataflowIntrinsics | ||
{ | ||
public static void Main () | ||
{ | ||
MakeGenericType.Test (); | ||
MakeGenericMethod.Test (); | ||
} | ||
|
||
class MakeGenericType | ||
{ | ||
class Gen<T> { } | ||
|
||
static Type GrabUnknownType () => null; | ||
|
||
public static void Test () | ||
{ | ||
TestRecognizedIntrinsic (); | ||
TestRecognizedGenericIntrinsic<object> (); | ||
TestUnknownOwningType (); | ||
TestUnknownArgument (); | ||
} | ||
|
||
public static void TestRecognizedIntrinsic () => typeof (Gen<>).MakeGenericType (typeof (object)); | ||
|
||
public static void TestRecognizedGenericIntrinsic<T> () => typeof (Gen<>).MakeGenericType (typeof (T)); | ||
|
||
[ExpectedWarning ("IL2055", nameof (Type.MakeGenericType))] | ||
[ExpectedWarning ("IL3050", nameof (Type.MakeGenericType), ProducedBy = Tool.Analyzer | Tool.NativeAot)] | ||
public static void TestUnknownOwningType () => GrabUnknownType ().MakeGenericType (typeof (object)); | ||
|
||
[ExpectedWarning ("IL3050", nameof (Type.MakeGenericType), ProducedBy = Tool.Analyzer | Tool.NativeAot)] | ||
public static void TestUnknownArgument () => typeof (Gen<>).MakeGenericType (GrabUnknownType ()); | ||
} | ||
|
||
class MakeGenericMethod | ||
{ | ||
public static void Gen<T> () { } | ||
|
||
static MethodInfo GrabUnknownMethod () => null; | ||
|
||
static Type GrabUnknownType () => null; | ||
|
||
public static void Test () | ||
{ | ||
TestRecognizedIntrinsic (); | ||
TestRecognizedGenericIntrinsic<object> (); | ||
TestUnknownOwningMethod (); | ||
TestUnknownArgument (); | ||
} | ||
|
||
public static void TestRecognizedIntrinsic () => typeof (MakeGenericMethod).GetMethod (nameof (Gen)).MakeGenericMethod (typeof (object)); | ||
|
||
public static void TestRecognizedGenericIntrinsic<T> () => typeof (MakeGenericMethod).GetMethod (nameof (Gen)).MakeGenericMethod (typeof (T)); | ||
|
||
[ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))] | ||
[ExpectedWarning ("IL3050", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Analyzer | Tool.NativeAot)] | ||
public static void TestUnknownOwningMethod () => GrabUnknownMethod ().MakeGenericMethod (typeof (object)); | ||
|
||
[ExpectedWarning ("IL3050", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Analyzer | Tool.NativeAot)] | ||
public static void TestUnknownArgument () => typeof (MakeGenericMethod).GetMethod (nameof (Gen)).MakeGenericMethod (GrabUnknownType()); | ||
} | ||
} | ||
} |