-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
MakeGenericType
generates wrong warning for annotation mismatch
#104911
Comments
I'm adding test for this case in dotnet/linker#2429. |
Note that this applies to Also note that if we fix this it is potentially a breaking change since we would be changing warning codes. So code which suppressed this warning, for example suppressing Not sure what the correct fix for this is, it might be that we use the warning level feature for the first time and only fix the warnings for .NET7+. |
My 2 cents: I would just fix it without complicating the codebase. I have doubts the warning waves feature will be useful. It works for Roslyn because it controls warnings generated for the C# code being compiled. For illink, the warning wave is chosen by the assembly being compiled, but it controls warnings for the entire application. We don't know what warning wave the referenced NuGets are compatible with. It may well be that come .NET 7, there will be NuGet packages generated with warning wave 7+ being used in .NET 6 apps. So the NuGet suppresses 2071, but the app gets 2070 because it's .NET 6. Putting the same compat burden on illink as is put on the C# compiler (orders of magnitude more users) might not be the best use of time. (I didn't actually even bother porting warning waves to NativeAOT yet.) |
That's a really good point - that linker mixes assemblies built by many different versions of the compiler and SDK. I guess we'll have to figure out how sensitive are we going to be to potentially breaking changes in the linker/NativeAOT. |
…tnet/linker#2429) Test for dotnet/linker#2428 Commit migrated from dotnet/linker@6a787f2
Tagging subscribers to this area: @dotnet/area-system-reflection |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas |
#104921 fixes this, including a change to the warning codes. This is a breaking change in the warning behavior, but only for code that isn't trim-compatible or that suppressed this warning. I think it's worth taking this breaking change, but since it is getting late in .NET 9 maybe it's better to do so early in .NET 10. Thoughts @vitek-karas @MichalStrehovsky? |
I think the only worry is the cases where somebody suppressed the warning specifically. Maybe we could search github for example for the old warning number and see if there are any cases like that. Otherwise, I think it would be OK to change even in 9 - especially since it will only affect projects which have 9.0 TFMs, so intentional upgrade. |
I didn't find any instances of IL2070 suppressions that specifically targeted this case, so it's probably rare this would break anyone. |
For example:
This generates a warning like:
This says that the "this" parameter for the
MakeGenericType
- which in this case thetypeof (GenericType)
as having requirements. That is not correct, the requirement comes from a generic parameter of that type. The warning should be:The bug is at this line:
https://github.com/dotnet/linker/blob/6880454ee1a29cb9e8239cb28d352228712661ee/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs#L1900
The target context should be the
genericParameter[i]
, not the method itself (which means "this" for that method).The text was updated successfully, but these errors were encountered: