Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings about Requires mismatch are not produced when DAM is used #70687

Closed
tlakollo opened this issue Jun 13, 2022 · 1 comment
Closed

Warnings about Requires mismatch are not produced when DAM is used #70687

tlakollo opened this issue Jun 13, 2022 · 1 comment
Assignees
Milestone

Comments

@tlakollo
Copy link
Contributor

tlakollo commented Jun 13, 2022

Description

The RequiresAttributeMismatch test uses DynamicallyAccessedMembersAttribute to mark as Required the methods on several classes by using a helper function called RequiresPublicMethods()
The classes are divided into Base/Derived classes and Virtual/Override classes, the attribute values inside these classes must match otherwise we should generate a warning stating that Base/Derive or Virtual/Override don't match.
Although NativeAOT warns about the usage of the methods being accessed by DAM, the attribute mismatch warnings are not existent.
Code that handles the attribute mismatch is in:

public static bool HasMismatchingAttributes (MethodDesc baseMethod, MethodDesc overridingMethod, string requiresAttributeName)
{
bool baseMethodCreatesRequirement = baseMethod.DoesMethodRequire(requiresAttributeName, out _);
bool overridingMethodCreatesRequirement = overridingMethod.DoesMethodRequire(requiresAttributeName, out _);
bool baseMethodFulfillsRequirement = baseMethod.IsOverrideInRequiresScope(requiresAttributeName);
bool overridingMethodFulfillsRequirement = overridingMethod.IsOverrideInRequiresScope(requiresAttributeName);
return (baseMethodCreatesRequirement && !overridingMethodFulfillsRequirement) || (overridingMethodCreatesRequirement && !baseMethodFulfillsRequirement);
}

Reproduction Steps

//These warnings for access are correctly generated
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
[ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
public static void Main ()
{
  typeof (BaseClassWithRequires).RequiresPublicMethods ();
  typeof (DerivedClassWithoutRequires).RequiresPublicMethods ();
}

class BaseClassWithRequires
{
  [RequiresUnreferencedCode ("Message")]
  [RequiresAssemblyFiles ("Message")]
  [RequiresDynamicCode ("Message")]
  public virtual void VirtualMethod ()
  {
  }
  
  public virtual string VirtualPropertyAnnotationInAccesor {
    [RequiresUnreferencedCode ("Message")]
    [RequiresAssemblyFiles ("Message")]
    [RequiresDynamicCode ("Message")]
    get;
    set;
  }
  
  [RequiresAssemblyFiles ("Message")]
  public virtual string VirtualPropertyAnnotationInProperty { get; set; }
  
  [RequiresAssemblyFiles ("Message")]
  public virtual string VirtualPropertyAnnotationInPropertyAndAccessor {
    [RequiresAssemblyFiles ("Message")]
    [RequiresUnreferencedCode ("Message")]
    get;
    set;
  }
}

class DerivedClassWithoutRequires : BaseClassWithRequires
{
  [ExpectedWarning ("IL2046", "DerivedClassWithoutRequires.VirtualMethod()", "BaseClassWithRequires.VirtualMethod()")]
  [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualMethod()", "BaseClassWithRequires.VirtualMethod()", ProducedBy = ProducedBy.Analyzer)]
  [ExpectedWarning ("IL3051", "DerivedClassWithoutRequires.VirtualMethod()", "BaseClassWithRequires.VirtualMethod()", ProducedBy = ProducedBy.Analyzer)]
  public override void VirtualMethod ()
  {
  }
  
  private string name;
  public override string VirtualPropertyAnnotationInAccesor {
    [ExpectedWarning ("IL2046", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
    [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
    [ExpectedWarning ("IL3051", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
    get { return name; }
    set { name = value; }
  }
  
  [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInProperty", "BaseClassWithRequires.VirtualPropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
  public override string VirtualPropertyAnnotationInProperty { get; set; }
  
  [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInPropertyAndAccessor", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor", ProducedBy = ProducedBy.Analyzer)]
  public override string VirtualPropertyAnnotationInPropertyAndAccessor {
    [ExpectedWarning ("IL2046", "VirtualPropertyAnnotationInPropertyAndAccessor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
    [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get", ProducedBy = ProducedBy.Analyzer)]
    get;
    set;
  }
}

Expected behavior

Generate IL2046, IL3003 and IL3051 depending on the Requires attribute being mismatched

Actual behavior

Only warnings for access are generated

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 13, 2022
@agocke agocke added this to AppModel Jun 14, 2022
@agocke agocke added this to the 7.0.0 milestone Jul 1, 2022
@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Jul 1, 2022
@tlakollo
Copy link
Contributor Author

Closed via #72496

@ghost ghost locked as resolved and limited conversation to collaborators Aug 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants