@@ -32,7 +32,6 @@ public static void Main ()
32
32
AnnotatedGenerics . Test ( ) ;
33
33
AnnotationOnGenerics . Test ( ) ;
34
34
AnnotationOnInteropMethod . Test ( ) ;
35
- AccessThroughLdToken . Test ( ) ;
36
35
}
37
36
38
37
class AnnotatedField
@@ -128,6 +127,17 @@ static void DynamicallyAccessedMembersNestedTypes2 ()
128
127
typeof ( AnnotatedField ) . RequiresNonPublicNestedTypes ( ) ;
129
128
}
130
129
130
+ static void PotentialWriteAccess ( ref Type type )
131
+ {
132
+ }
133
+
134
+ // https://github.com/dotnet/linker/issues/3172
135
+ [ ExpectedWarning ( "IL2110" , nameof ( AnnotatedField . _annotatedField ) , ProducedBy = ProducedBy . Trimmer ) ]
136
+ static void LdToken ( )
137
+ {
138
+ Expression < Action > a = ( ) => PotentialWriteAccess ( ref _annotatedField ) ;
139
+ }
140
+
131
141
[ UnconditionalSuppressMessage ( "test" , "IL2026" ) ]
132
142
public static void Test ( )
133
143
{
@@ -143,6 +153,7 @@ public static void Test ()
143
153
DynamicallyAccessedMembersAll2 ( ) ;
144
154
DynamicallyAccessedMembersNestedTypes1 ( ) ;
145
155
DynamicallyAccessedMembersNestedTypes2 ( ) ;
156
+ LdToken ( ) ;
146
157
}
147
158
}
148
159
@@ -251,6 +262,14 @@ static void DynamicallyAccessedMembersAll2 ()
251
262
typeof ( AnnotatedMethodParameters ) . RequiresAll ( ) ;
252
263
}
253
264
265
+ // https://github.com/dotnet/linker/issues/3172
266
+ [ ExpectedWarning ( "IL2111" , nameof ( MethodWithSingleAnnotatedParameter ) , ProducedBy = ProducedBy . Trimmer ) ]
267
+ [ ExpectedWarning ( "IL2067" , nameof ( MethodWithSingleAnnotatedParameter ) , ProducedBy = ProducedBy . Analyzer ) ]
268
+ static void LdToken ( )
269
+ {
270
+ Expression < Action < Type > > _ = ( Type t ) => MethodWithSingleAnnotatedParameter ( t ) ;
271
+ }
272
+
254
273
[ UnconditionalSuppressMessage ( "test" , "IL2026" ) ]
255
274
public static void Test ( )
256
275
{
@@ -265,6 +284,7 @@ public static void Test ()
265
284
Ldvirtftn ( ) ;
266
285
DynamicallyAccessedMembersAll1 ( ) ;
267
286
DynamicallyAccessedMembersAll2 ( ) ;
287
+ LdToken ( ) ;
268
288
}
269
289
}
270
290
@@ -363,6 +383,18 @@ static void LdftnOnVirtual ()
363
383
var _ = new Func < Type > ( ( new AnnotatedMethodReturnValue ( ) ) . VirtualMethodWithAnnotatedReturnValue ) ;
364
384
}
365
385
386
+ static void LdTokenOnStatic ( )
387
+ {
388
+ Expression < Action > _ = ( ) => StaticMethodWithAnnotatedReturnValue ( ) ;
389
+ }
390
+
391
+ // https://github.com/dotnet/linker/issues/3172
392
+ [ ExpectedWarning ( "IL2111" , nameof ( VirtualMethodWithAnnotatedReturnValue ) , ProducedBy = ProducedBy . Trimmer ) ]
393
+ static void LdTokenOnVirtual ( )
394
+ {
395
+ Expression < Action < AnnotatedMethodReturnValue > > _ = ( a ) => a . VirtualMethodWithAnnotatedReturnValue ( ) ;
396
+ }
397
+
366
398
[ UnconditionalSuppressMessage ( "test" , "IL2026" ) ]
367
399
public static void Test ( )
368
400
{
@@ -380,6 +412,8 @@ public static void Test ()
380
412
LdftnOnStatic ( ) ;
381
413
LdftnOnInstance ( ) ;
382
414
LdftnOnVirtual ( ) ;
415
+ LdTokenOnStatic ( ) ;
416
+ LdTokenOnVirtual ( ) ;
383
417
}
384
418
}
385
419
@@ -563,6 +597,13 @@ static void DynamicallyAccessedFields ()
563
597
typeof ( AnnotatedProperty ) . RequiresNonPublicFields ( ) ;
564
598
}
565
599
600
+ // Action delegate is not handled correctly https://github.com/dotnet/linker/issues/2561
601
+ [ ExpectedWarning ( "IL2111" , nameof ( Property1WithAnnotation ) , ProducedBy = ProducedBy . Trimmer ) ]
602
+ static void LdToken ( )
603
+ {
604
+ Expression < Func < Type > > _ = ( ) => Property1WithAnnotation ;
605
+ }
606
+
566
607
[ UnconditionalSuppressMessage ( "test" , "IL2026" ) ]
567
608
public static void Test ( )
568
609
{
@@ -581,6 +622,7 @@ public static void Test ()
581
622
DynamicallyAccessedMembersAll1 ( ) ;
582
623
DynamicallyAccessedMembersAll2 ( ) ;
583
624
DynamicallyAccessedFields ( ) ;
625
+ LdToken ( ) ;
584
626
}
585
627
}
586
628
@@ -623,13 +665,20 @@ static void DynamicallyAccessedMembersAll ()
623
665
typeof ( AnnotatedGenerics ) . RequiresAll ( ) ;
624
666
}
625
667
668
+ [ ExpectedWarning ( "IL2091" , nameof ( GenericWithAnnotation ) ) ]
669
+ static void LdToken < TUnknown > ( )
670
+ {
671
+ Expression < Action > _ = ( ) => GenericWithAnnotation < TUnknown > ( ) ;
672
+ }
673
+
626
674
public static void Test ( )
627
675
{
628
676
ReflectionOnly ( ) ;
629
677
DynamicDependency ( ) ;
630
678
DynamicallyAccessedMembers ( ) ;
631
679
InstantiateGeneric ( ) ;
632
680
DynamicallyAccessedMembersAll ( ) ;
681
+ LdToken < string > ( ) ;
633
682
}
634
683
}
635
684
@@ -693,6 +742,17 @@ static void DynamicallyAccessedMembersAll2 ()
693
742
typeof ( AnnotationOnGenerics ) . RequiresAll ( ) ;
694
743
}
695
744
745
+ // https://github.com/dotnet/linker/issues/3172
746
+ [ ExpectedWarning ( "IL2111" , "GenericWithAnnotatedMethod" , "AnnotatedMethod" , ProducedBy = ProducedBy . Trimmer ) ]
747
+ static void LdToken ( )
748
+ {
749
+ // Note that this should warn even though the code looks "Correct"
750
+ // That is because under the hood the expression tree create MethodInfo which is accessible by anything
751
+ // which gets the expression tree as input (so some queryable) and that could invoke the method
752
+ // with a different parameter value and thus violate the requirements.
753
+ Expression < Action > _ = ( ) => GenericWithAnnotatedMethod < TestType > . AnnotatedMethod ( typeof ( TestType ) ) ;
754
+ }
755
+
696
756
public static void Test ( )
697
757
{
698
758
GenericTypeWithStaticMethodViaLdftn ( ) ;
@@ -702,6 +762,7 @@ public static void Test ()
702
762
GenericMethodDynamicallyAccessedMembers ( ) ;
703
763
DynamicallyAccessedMembersAll1 ( ) ;
704
764
DynamicallyAccessedMembersAll2 ( ) ;
765
+ LdToken ( ) ;
705
766
}
706
767
}
707
768
@@ -713,12 +774,12 @@ struct ValueWithAnnotatedField
713
774
public Type _typeField ;
714
775
}
715
776
716
- // Analyzer doesnt take into account interop attributes https://github.com/dotnet/linker/issues/2562
777
+ // Analyzer doesn't take into account interop attributes https://github.com/dotnet/linker/issues/2562
717
778
[ ExpectedWarning ( "IL2110" , nameof ( ValueWithAnnotatedField . _typeField ) , ProducedBy = ProducedBy . Trimmer ) ]
718
779
[ DllImport ( "nonexistent" ) ]
719
780
static extern ValueWithAnnotatedField GetValueWithAnnotatedField ( ) ;
720
781
721
- // Analyzer doesnt take into account interop attributes https://github.com/dotnet/linker/issues/2562
782
+ // Analyzer doesn't take into account interop attributes https://github.com/dotnet/linker/issues/2562
722
783
[ ExpectedWarning ( "IL2110" , nameof ( ValueWithAnnotatedField . _typeField ) , ProducedBy = ProducedBy . Trimmer ) ]
723
784
[ DllImport ( "nonexistent" ) ]
724
785
static extern void AcceptValueWithAnnotatedField ( ValueWithAnnotatedField value ) ;
@@ -730,24 +791,6 @@ public static void Test ()
730
791
}
731
792
}
732
793
733
- class AccessThroughLdToken
734
- {
735
- public virtual Type PropertyWithLdToken {
736
- [ return : DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ]
737
- get {
738
- return null ;
739
- }
740
- }
741
-
742
- // Action delegate is not handled correctly https://github.com/dotnet/linker/issues/2561
743
- [ ExpectedWarning ( "IL2111" , nameof ( PropertyWithLdToken ) , ProducedBy = ProducedBy . Trimmer ) ]
744
- [ ExpectedWarning ( "IL2111" , nameof ( PropertyWithLdToken ) , ProducedBy = ProducedBy . Trimmer ) ]
745
- public static void Test ( )
746
- {
747
- Expression < Func < Type > > getter = ( ) => ( new AccessThroughLdToken ( ) ) . PropertyWithLdToken ;
748
- }
749
- }
750
-
751
794
public class AnnotatedAttributeConstructorAttribute : Attribute
752
795
{
753
796
public AnnotatedAttributeConstructorAttribute ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . All ) ] Type type )
0 commit comments