-
Notifications
You must be signed in to change notification settings - Fork 127
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
ILLink analyzer hole for deconstruction assignments #3158
Comments
Also I do not get why Linker tries to trim referenced assemblies (Hangfire.AspNetCore for example) even when |
Ok, I know why |
There are some differences between the analyzer and the trimmer - we try to minimize these, but it's not always possible (or easy). But it could also be a bug. The general strategy is:
Based on the error this is around compiler generated code. That is one area where the analyzer is more likely to "understand" - because it sees the code mostly as written by the user. Unlike the trimmer which sees the compiler generated IL which implements the user's code - sometimes in a rather complex manner. We've been working on this area a lot, but it could be here are still bugs there. What version of the SDK/trimmer are you using? Ideally the version of the .NET SDK and the target framework for the app ( Also - if you have a repro project available, we could look into this some more. Or at least the piece of code where the warning is generated. |
.NET 7, "C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.ILLink.Tasks\tools\net7.0\illink.dll |
Do you mind, if I add you as a colaborator to the project? |
No, but I don't see a reason - I won't try to find the right magic to workaround this problem - even if it worked, it would likely break with your next change to any code remotely around it. |
It's ok, but at least we'll know the reason for this behavior. ;-) |
Done. If you try to publish API as self contained, it will fail. branch: feature/small-self-contained-container |
Sorry - I was confused between two different issues, so my answer above is a bit weird. Thanks for the repro - I'll take a look. |
I filed a new issue in that repo to discuss the details - please take a look. |
To the specific issue reported in this bug where linker warns but analyzer doesn't. This is a bug in the analyzer. The pattern is actually pretty simple: static void DeconstructVariableNoAnnotation ((Type type, object instance) input)
{
var (type, instance) = input; // This is the problematic spot
type.RequiresPublicMethods (); // Should warn IL2077 - linker does, analyzer doesn't
} The problem is the deconstruction statement. Analyzer doesn't recognize it as something which assigns values to locals and so it enters the second line with having two locals The root problem is that the visitor doesn't handle I'll prepare a simple test and merge that first - so that we have something to test the existing behavior (linker warns, analyzer doesn't). Workaround (if you can call it that) is to not use deconstructions and instead refer to the items of the constructed type as properties - so the same code can be rewritten like: static void DeconstructVariableNoAnnotation ((Type type, object instance) input)
{
input.type.RequiresPublicMethods (); // Warns IL2077 in both linker and analyzer
} But this is just a pure bug in the analyzer and we need to fix this. |
#3164 adds tests which cover these cases. |
This was prompted by #3158 So I just added several tests for various shapes of type deconstructions. To make it symmetric I also added tests for what I call type construction (tuples, anonymous types, records).
This was prompted by dotnet/linker#3158 So I just added several tests for various shapes of type deconstructions. To make it symmetric I also added tests for what I call type construction (tuples, anonymous types, records). Commit migrated from dotnet/linker@72d05e4
I get an error when I'm trying to publish an assembly:
However, analyzer does not emit any warnings when building the project (
dotnet build /p:PublishTrimmed=true
), yet I haveTreatWarningsAsErrors=true
.What can be the reason for it?
Project is targeting .NET, I see ILLink.RoslynAnalyzer among referenced analyzers, severity for IL2080 is set to error.
The text was updated successfully, but these errors were encountered: