-
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
ILLink: FormatException when building a diagnostic message #93800
Comments
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsRepro:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishTrimmed>true</PublishTrimmed>
<WarningsAsErrors>false</WarningsAsErrors>
<NoWarn>NU1605;NU1603;NU1701</NoWarn>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="AltV.Net.Shared" />
<PackageReference Include="AltV.Net.Shared" Version="14.0.2-dev" />
</ItemGroup>
</Project>
Stacktrace from the build:
|
Simple repro: static Type UnannotatedField;
static void MakeGenericNullableOfUnannotatedFieldRequiresPublicProperties ()
{
// Expected IL2087 (currently)
typeof (Nullable<>).MakeGenericType (UnannotatedField).RequiresPublicProperties ();
} The bug is in runtime/src/tools/illink/src/ILLink.Shared/Annotations.cs Lines 114 to 118 in 7c8fff9
The code which maps the source/target pair values to the Diagnostic ID treats This is wrong because the formatted message will not make any sense. For example: void DoIt(Type p1)
{
typeof(Nullable<>).MakeGenericType(p1).GetProperties();
} Will produce:
Specifically I think the correct behavior is to unwrap |
The problem with the proposed fix is, that it would change warning codes reported for these cases. Which is a breaking change.
I think we do need to fix this, as in, we must not crash the trimmer in this case. One last alternative would be to special case this specific situation (nullable over field) and in that case produce a warning with a different code. Current behavior:
Because of this, the specific case with nullable over field is basically not used in 8 - The only way to get the warning is in analyzer, both trimmer and AOT won't produce it (they crash). So changing the warning code in this specific case might be acceptable, as it's basically a change from crash to working. Unfortunately this would mean we leave the other cases with wrong messages (see above). |
Note that we've shipped this in 7.0 trimmer already, so rushing a real fix into 8.0 servicing would not reduce the potential impact of the breaking change. |
…ormatting diagnostics (#110229) Fixes #109536 See #93800 for more context. When a NullableValue is the source of an assignment, we consider use the TypeArgumentTargetsX diagnostic since the underlying value is a generic argument, but use the source of the generic argument for diagnostics. This leads to some confusing warning messages, and sometimes crashes in formatting the diagnostics. Ideally, we would want to unwrap the NullableValues and use the UnderlyingTypeValue as the source, but this would be a breaking change for the situations that don't crash. FieldValue and MethodReturnValue only provide 1 diagnostic arguments, but the diagnostics for TypeArgumentTargetsX expects 2 arguments from the source. This caused crashes when the situation was encountered. Since they didn't work before at all, this won't be a breaking change to provide the correct warning here.
Repro:
dotnet new console
app.csproj
:dotnet publish
Stacktrace from the build:
/cc @LakshanF
The text was updated successfully, but these errors were encountered: