-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-NativeAOT-coreclrneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Description
Description
Doing some testing with the Requires attribute on CompilerGeneratedCode I realized that NativeAOT has differences with linker, it will not produce warnings for code using ldftn for example:
//[ExpectedWarning("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
//[ExpectedWarning("IL3050", "--MethodWithRequires--")]
static IEnumerable<int> TestLdftn()
{
yield return 0;
yield return 1;
var action = new Action(MethodWithRequires);
}
[RequiresUnreferencedCode("--MethodWithRequires--")]
[RequiresDynamicCode("--MethodWithRequires--")]
static void MethodWithRequires()
{
}It will have problems with Lazy Delegates too
// Cannot annotate fields either with RUC nor RAF therefore the warning persists
//[ExpectedWarning("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
//[ExpectedWarning("IL3050", "Message from --MethodWithRequiresAndReturns--")]
public static Lazy<string> _default = new Lazy<string>(MethodWithRequiresAndReturns);
static IEnumerable<int> TestLazyDelegate()
{
yield return 0;
yield return 1;
_ = _default.Value;
}
[RequiresUnreferencedCode("Message from --MethodWithRequiresAndReturns--")]
[RequiresDynamicCode("Message from --MethodWithRequiresAndReturns--")]
public static string MethodWithRequiresAndReturns()
{
return "string";
}Suppression inside CompilerGeneratedCode is also not working
Reproduction Steps
- Copy the RequiresInCompilerGeneratedCode code in dotnet/linker and paste into the NativeAOT Program.cs
- Comment the ExpectedWarning attributes since there is no support for the attribute in NativeAOT
- Execute the program.cs following the instructions in https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/nativeaot.md#running-tests
- Review the warnings generated vs the ExpectedWarnings manually
Expected behavior
The warnings generated by dotnet/linker and nativeAOT should be the same
Actual behavior
NativeAOT sometimes misses generating some of the warnings and some other times it generates extra warnings
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Metadata
Metadata
Assignees
Labels
area-NativeAOT-coreclrneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Type
Projects
Status
High Priority