-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
static void Method(Type[] interfaces) {
foreach (Type i in interfaces)
i.GetMethods(); // warning here. IL2075 for analyzer, IL2065 for ILLink
}
The ILLink Roslyn analyzer produces IL2075 (unannotated method return value flows to 'this' parameter with requirements), because it sees the return value of Current.get
used as the receiver for GetMethods
.
ILLink produces IL2065 ('this' parameter cannot be statically determined), because when it sees ldelem.ref
of the array method parameter, it turns this into an "unknown" value, which has a different warning code.
Fundamentally this is due to the analyzer seeing a different lowering of the foreach loop than illink. Fixing this seems tricky.
Found while investigating #96462. There's an existing testcase similar to this:
runtime/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
Lines 443 to 453 in 0451127
[ExpectedWarning ("IL2063", ProducedBy = Tool.Trimmer)] // The types loaded from the array don't have annotations, so the "return" should warn | |
[ExpectedWarning ("IL2073", ProducedBy = Tool.Analyzer)] // Analyzer tracks resultType as the value from IEnumerable.Current.get() | |
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | |
public static Type TestBackwardEdgeWithLdElem (Type[] types = null) | |
{ | |
Type resultType = null; | |
foreach (var type in types) { | |
resultType = type; | |
} | |
return resultType; |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status