@@ -681,6 +681,21 @@ static void TestCall ()
681681 void LocalFunction ( ) => MethodWithRequires ( ) ;
682682 }
683683
684+ [ RequiresUnreferencedCode ( "Suppress in body" ) ]
685+ [ RequiresAssemblyFiles ( "Suppress in body" ) ]
686+ [ RequiresDynamicCode ( "Suppress in body" ) ]
687+ static void TestCallFromNestedLocalFunction ( )
688+ {
689+ LocalFunction ( ) ;
690+
691+ void LocalFunction ( )
692+ {
693+ NestedLocalFunction ( ) ;
694+
695+ void NestedLocalFunction ( ) => MethodWithRequires ( ) ;
696+ }
697+ }
698+
684699 [ RequiresUnreferencedCode ( "Suppress in body" ) ]
685700 [ RequiresAssemblyFiles ( "Suppress in body" ) ]
686701 [ RequiresDynamicCode ( "Suppress in body" ) ]
@@ -870,7 +885,7 @@ public static void TestCallMethodWithRequiresInDynamicallyAccessedLocalFunction
870885 [ ExpectedWarning ( "IL2026" ) ]
871886 [ ExpectedWarning ( "IL3002" , ProducedBy = ProducedBy . Analyzer ) ]
872887 [ ExpectedWarning ( "IL3050" , ProducedBy = ProducedBy . Analyzer ) ]
873- static void TestSuppressionLocalFunction ( )
888+ static void TestSuppressionOnLocalFunction ( )
874889 {
875890 LocalFunction ( ) ; // This will produce a warning since the local function has Requires on it
876891
@@ -884,6 +899,27 @@ void LocalFunction (Type unknownType = null)
884899 }
885900 }
886901
902+ [ ExpectedWarning ( "IL2026" ) ]
903+ [ ExpectedWarning ( "IL3002" , ProducedBy = ProducedBy . Analyzer ) ]
904+ [ ExpectedWarning ( "IL3050" , ProducedBy = ProducedBy . Analyzer ) ]
905+ static void TestSuppressionOnLocalFunctionWithNestedLocalFunction ( )
906+ {
907+ LocalFunction ( ) ; // This will produce a warning since the local function has Requires on it
908+
909+ [ RequiresUnreferencedCode ( "Suppress in body" ) ]
910+ [ RequiresAssemblyFiles ( "Suppress in body" ) ]
911+ [ RequiresDynamicCode ( "Suppress in body" ) ]
912+ void LocalFunction ( )
913+ {
914+ NestedLocalFunction ( ) ;
915+
916+ // The linker doesn't have enough information to associate the RUC on LocalFunction
917+ // with this nested local function.
918+ [ ExpectedWarning ( "IL2026" , ProducedBy = ProducedBy . Trimmer ) ]
919+ void NestedLocalFunction ( ) => MethodWithRequires ( ) ;
920+ }
921+ }
922+
887923 [ RequiresUnreferencedCode ( "Suppress in body" ) ]
888924 [ RequiresAssemblyFiles ( "Suppress in body" ) ]
889925 [ RequiresDynamicCode ( "Suppress in body" ) ]
@@ -939,6 +975,7 @@ static void Outer (int i)
939975 public static void Test ( )
940976 {
941977 TestCall ( ) ;
978+ TestCallFromNestedLocalFunction ( ) ;
942979 TestCallWithClosure ( ) ;
943980 TestReflectionAccess ( ) ;
944981 TestLdftn ( ) ;
@@ -954,7 +991,8 @@ public static void Test ()
954991 TestCallMethodWithRequiresInLtftnLocalFunction ( ) ;
955992 DynamicallyAccessedLocalFunction . TestCallMethodWithRequiresInDynamicallyAccessedLocalFunction ( ) ;
956993 DynamicallyAccessedLocalFunctionUnused . TestCallMethodWithRequiresInDynamicallyAccessedLocalFunction ( ) ;
957- TestSuppressionLocalFunction ( ) ;
994+ TestSuppressionOnLocalFunction ( ) ;
995+ TestSuppressionOnLocalFunctionWithNestedLocalFunction ( ) ;
958996 TestSuppressionOnOuterAndLocalFunction ( ) ;
959997 TestSuppressionOnOuterWithSameName . Test ( ) ;
960998 }
@@ -1075,6 +1113,16 @@ static void TestCall ()
10751113 ( ) => MethodWithRequires ( ) ;
10761114 }
10771115
1116+ [ RequiresUnreferencedCode ( "Suppress in body" ) ]
1117+ [ RequiresAssemblyFiles ( "Suppress in body" ) ]
1118+ [ RequiresDynamicCode ( "Suppress in body" ) ]
1119+ static void TestCallFromNestedLambda ( )
1120+ {
1121+ Action lambda = ( ) => {
1122+ Action nestedLambda = ( ) => MethodWithRequires ( ) ;
1123+ } ;
1124+ }
1125+
10781126 [ RequiresUnreferencedCode ( "Suppress in body" ) ]
10791127 [ RequiresAssemblyFiles ( "Suppress in body" ) ]
10801128 [ RequiresDynamicCode ( "Suppress in body" ) ]
@@ -1192,6 +1240,26 @@ static void TestSuppressionOnLambda ()
11921240 lambda ( ) ; // This will produce a warning since the lambda has Requires on it
11931241 }
11941242
1243+ [ ExpectedWarning ( "IL2026" ) ]
1244+ [ ExpectedWarning ( "IL3002" , ProducedBy = ProducedBy . Analyzer ) ]
1245+ [ ExpectedWarning ( "IL3050" , ProducedBy = ProducedBy . Analyzer ) ]
1246+ static void TestSuppressionOnLambdaWithNestedLambda ( )
1247+ {
1248+ var lambda =
1249+ [ RequiresUnreferencedCode ( "Suppress in body" ) ]
1250+ [ RequiresAssemblyFiles ( "Suppress in body" ) ]
1251+ [ RequiresDynamicCode ( "Suppress in body" ) ]
1252+ ( ) => {
1253+ // The linker doesn't have enough information to associate the RUC on lambda
1254+ // with this nested lambda.
1255+ var nestedLambda =
1256+ [ ExpectedWarning ( "IL2026" , ProducedBy = ProducedBy . Trimmer ) ]
1257+ ( ) => MethodWithRequires ( ) ;
1258+ } ;
1259+
1260+ lambda ( ) ; // This will produce a warning since the local function has Requires on it
1261+ }
1262+
11951263 [ RequiresUnreferencedCode ( "Suppress in body" ) ]
11961264 [ RequiresAssemblyFiles ( "Suppress in body" ) ]
11971265 [ RequiresDynamicCode ( "Suppress in body" ) ]
@@ -1249,6 +1317,7 @@ static void Outer (int i)
12491317 public static void Test ( )
12501318 {
12511319 TestCall ( ) ;
1320+ TestCallFromNestedLambda ( ) ;
12521321 TestCallWithReflectionAnalysisWarning ( ) ;
12531322 TestCallWithClosure ( ) ;
12541323 TestReflectionAccess ( ) ;
@@ -1259,6 +1328,7 @@ public static void Test ()
12591328 TestGenericMethodParameterRequirement < TestType > ( ) ;
12601329 TestGenericTypeParameterRequirement < TestType > ( ) ;
12611330 TestSuppressionOnLambda ( ) ;
1331+ TestSuppressionOnLambdaWithNestedLambda ( ) ;
12621332 TestSuppressionOnOuterAndLambda ( ) ;
12631333 TestSuppressionOnOuterWithSameName . Test ( ) ;
12641334 }
0 commit comments