-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Milestone
Description
Description
I am observing an IL2067 warning which makes no sense to me, in that it mentions 'DynamicallyAccessedMemberTypes on a record parameter which doesn't have [DynamicallyAccessedMembers].
Reproduction Steps
Consider the following code:
using System.Diagnostics.CodeAnalysis;
record ViewMap(
Func<Type?>? ViewSelector = null,
[property: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Type? ViewModel = null,
object? Data = null
);
record MessageDialogViewMap(
[param: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicConstructors)]
Type? ViewModel = default,
object? Data = default
): ViewMap(
ViewModel: ViewModel,
Data: Data
);Note that ViewMap.ViewModel has [DynamicallyAccessedMembers], while ViewModel.Data does not.
Build the project:
dotnet build -bl -p:IsTrimmable=true
It warns:
MyRecord.cs(15,4): warning IL2067: 'ViewModel' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'ViewMap.ViewMap(Func<Type>, Type, Object)'. The parameter 'Data' of method 'MessageDialogViewMap.MessageDialogViewMap(Type, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
Note The parameter 'Data' … does not have matching annotations. Data doesn't have any annotations! There's nothing to match!
Expected behavior
No warnings.
Actual behavior
An IL2067 warning (see Reproduction Steps).
Regression?
No response
Known Workarounds
Provide all the parameters to the base constructor invocation. This compiles without warning:
record MessageDialogViewMap(
[param: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicConstructors)]
Type? ViewModel = default,
object? Data = default
): ViewMap(
ViewSelector: null,
ViewModel: ViewModel,
Data: Data
);Configuration
No response
Other information
No response
Copilot
Metadata
Metadata
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Type
Projects
Status
No status