@@ -1616,20 +1616,6 @@ void ReportWarningsForReflectionAccess (in MessageOrigin origin, MethodDefinitio
1616
1616
break ;
1617
1617
}
1618
1618
}
1619
-
1620
- // Warn on reflection access to compiler-generated methods, if the method isn't already unsafe to access via reflection
1621
- // due to annotations. For the annotation-based warnings, we skip virtual overrides since those will produce warnings on
1622
- // the base, but for unannotated compiler-generated methods this is not the case, so we must produce these warnings even
1623
- // for virtual overrides. This ensures that we include the unannotated MoveNext state machine method. Lambdas and local
1624
- // functions should never be virtual overrides in the first place.
1625
- bool isCoveredByAnnotations = isReflectionAccessCoveredByRUC || isReflectionAccessCoveredByDAM ;
1626
- switch ( dependencyKind ) {
1627
- case DependencyKind . AccessedViaReflection :
1628
- case DependencyKind . DynamicallyAccessedMember :
1629
- if ( ShouldWarnForReflectionAccessToCompilerGeneratedCode ( method , isCoveredByAnnotations ) )
1630
- Context . LogWarning ( origin , DiagnosticId . CompilerGeneratedMemberAccessedViaReflection , method . GetDisplayName ( ) ) ;
1631
- break ;
1632
- }
1633
1619
}
1634
1620
1635
1621
void ReportWarningsForTypeHierarchyReflectionAccess ( IMemberDefinition member , MessageOrigin origin )
@@ -1672,23 +1658,6 @@ static bool IsDeclaredWithinType (IMemberDefinition member, TypeDefinition type)
1672
1658
var id = reportOnMember ? DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesMemberWithDynamicallyAccessedMembers : DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesMemberOnBaseWithDynamicallyAccessedMembers ;
1673
1659
Context . LogWarning ( origin , id , type . GetDisplayName ( ) , ( ( MemberReference ) member ) . GetDisplayName ( ) ) ;
1674
1660
}
1675
-
1676
- // Warn on reflection access to compiler-generated methods, if the method isn't already unsafe to access via reflection
1677
- // due to annotations. For the annotation-based warnings, we skip virtual overrides since those will produce warnings on
1678
- // the base, but for unannotated compiler-generated methods this is not the case, so we must produce these warnings even
1679
- // for virtual overrides. This ensures that we include the unannotated MoveNext state machine method. Lambdas and local
1680
- // functions should never be virtual overrides in the first place.
1681
- bool isCoveredByAnnotations = isReflectionAccessCoveredByRUC || isReflectionAccessCoveredByDAM ;
1682
- if ( member is MethodDefinition method && ShouldWarnForReflectionAccessToCompilerGeneratedCode ( method , isCoveredByAnnotations ) ) {
1683
- var id = reportOnMember ? DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesCompilerGeneratedMember : DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesCompilerGeneratedMemberOnBase ;
1684
- Context . LogWarning ( origin , id , type . GetDisplayName ( ) , method . GetDisplayName ( ) ) ;
1685
- }
1686
-
1687
- // Warn on reflection access to compiler-generated fields.
1688
- if ( member is FieldDefinition field && ShouldWarnForReflectionAccessToCompilerGeneratedCode ( field , isCoveredByAnnotations ) ) {
1689
- var id = reportOnMember ? DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesCompilerGeneratedMember : DiagnosticId . DynamicallyAccessedMembersOnTypeReferencesCompilerGeneratedMemberOnBase ;
1690
- Context . LogWarning ( origin , id , type . GetDisplayName ( ) , field . GetDisplayName ( ) ) ;
1691
- }
1692
1661
}
1693
1662
1694
1663
void MarkField ( FieldDefinition field , in DependencyInfo reason , in MessageOrigin origin )
@@ -1752,24 +1721,6 @@ void MarkField (FieldDefinition field, in DependencyInfo reason, in MessageOrigi
1752
1721
}
1753
1722
}
1754
1723
1755
- bool ShouldWarnForReflectionAccessToCompilerGeneratedCode ( FieldDefinition field , bool isCoveredByAnnotations )
1756
- {
1757
- // No need to warn if it's already covered by the Requires attribute or explicit annotations on the field.
1758
- if ( isCoveredByAnnotations )
1759
- return false ;
1760
-
1761
- if ( ! CompilerGeneratedState . IsNestedFunctionOrStateMachineMember ( field ) )
1762
- return false ;
1763
-
1764
- // Only warn for types which are interesting for dataflow. Note that this does
1765
- // not include integer types, even though we track integers in the dataflow analysis.
1766
- // Technically we should also warn for integer types, but this leads to more warnings
1767
- // for example about the compiler-generated "state" field for state machine methods.
1768
- // This should be ok because in most cases the state machine types will also have other
1769
- // hoisted locals that produce warnings anyway when accessed via reflection.
1770
- return Annotations . FlowAnnotations . IsTypeInterestingForDataflow ( field . FieldType ) ;
1771
- }
1772
-
1773
1724
void ProcessAnalysisAnnotationsForField ( FieldDefinition field , DependencyKind dependencyKind , in MessageOrigin origin )
1774
1725
{
1775
1726
switch ( dependencyKind ) {
@@ -1790,32 +1741,21 @@ void ProcessAnalysisAnnotationsForField (FieldDefinition field, DependencyKind d
1790
1741
if ( Annotations . ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode ( origin . Provider , out _ ) )
1791
1742
return ;
1792
1743
1793
- bool isReflectionAccessCoveredByRUC ;
1794
- if ( isReflectionAccessCoveredByRUC = Annotations . ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode ( field , out RequiresUnreferencedCodeAttribute ? requiresUnreferencedCodeAttribute ) )
1744
+ if ( Annotations . ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode ( field , out RequiresUnreferencedCodeAttribute ? requiresUnreferencedCodeAttribute ) )
1795
1745
ReportRequiresUnreferencedCode ( field . GetDisplayName ( ) , requiresUnreferencedCodeAttribute ! , new DiagnosticContext ( origin , diagnosticsEnabled : true , Context ) ) ;
1796
1746
1797
- bool isReflectionAccessCoveredByDAM = false ;
1798
1747
switch ( dependencyKind ) {
1799
1748
case DependencyKind . AccessedViaReflection :
1800
1749
case DependencyKind . DynamicDependency :
1801
1750
case DependencyKind . DynamicallyAccessedMember :
1802
1751
case DependencyKind . InteropMethodDependency :
1803
1752
case DependencyKind . Ldtoken :
1804
1753
case DependencyKind . UnsafeAccessorTarget :
1805
- if ( isReflectionAccessCoveredByDAM = Annotations . FlowAnnotations . ShouldWarnWhenAccessedForReflection ( field ) )
1754
+ if ( Annotations . FlowAnnotations . ShouldWarnWhenAccessedForReflection ( field ) )
1806
1755
Context . LogWarning ( origin , DiagnosticId . DynamicallyAccessedMembersFieldAccessedViaReflection , field . GetDisplayName ( ) ) ;
1807
1756
1808
1757
break ;
1809
1758
}
1810
-
1811
- switch ( dependencyKind ) {
1812
- case DependencyKind . AccessedViaReflection :
1813
- case DependencyKind . DynamicallyAccessedMember :
1814
- bool isCoveredByAnnotations = isReflectionAccessCoveredByRUC || isReflectionAccessCoveredByDAM ;
1815
- if ( ShouldWarnForReflectionAccessToCompilerGeneratedCode ( field , isCoveredByAnnotations ) )
1816
- Context . LogWarning ( origin , DiagnosticId . CompilerGeneratedMemberAccessedViaReflection , field . GetDisplayName ( ) ) ;
1817
- break ;
1818
- }
1819
1759
}
1820
1760
1821
1761
/// <summary>
0 commit comments