Open eerhardt opened 10 months ago
Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.
Author: | eerhardt |
---|---|
Assignees: | - |
Labels: | `area-Extensions-Configuration` |
Milestone: | - |
That's surprising, doesn't the generated code suppress nullability warnings in source?
That's surprising, doesn't the generated code suppress nullability warnings in source?
No, it explicitly enables it:
That seems surprising given that this was picked up from the JSON generator:
I think we should consistently disable nullability warnings in all generated code (except perhaps in debug builds of the generator?)
@eerhardt I'm preparing a PR that disables nullability warnings in generated code. I'm not super familiar with this library though, do you know if there's a minimal repro I can use that doesn't require the dependency on Polly?
Unfortunately, no I don't. I haven't had time to pare it down.
I would try making a type of Func<HedgingActionGeneratorArguments<TResult>, Func<ValueTask<Outcome<TResult>>>?>
where HedgingActionGeneratorArguments and Outcome are generic types.
Is that warning a side-effect of the generator erroneously generating binding code for delegate types?
Yes, but I believe the issue will also occur if you replace the Func
with some other generic types.
This was addressed in .NET 8 via https://github.com/dotnet/runtime/pull/94267 by disabling nullability warnings altogether. Moving to Future for a fix that addresses the specific annotation issue.
Moving to 10.0.0
Description
When attempting to use the ConfigurationBinder source generator in dotnet/extensions (see https://github.com/dotnet/extensions/pull/4625), I'm getting a nullable warning that is causing the generated code to not compile (I would need to disable nullable validation for the whole project if I wanted to ignore the nullable warning, which isn't acceptable).
I'm not sure what the general pattern is here that causes this issue, so I logged the issue for the scenario specifically. I think it might need to include nested generics where one of the nested generic types is nullable.
Reproduction Steps
Expected behavior
Should be without warnings
Actual behavior
Get a nullable warning from generated code:
The generated code looks like:
That middle line is the issue, it is of type:
Func<HedgingActionGeneratorArguments<HttpResponseMessage>, Func<ValueTask<Outcome<HttpResponseMessage>>>>
but the type ofinstance.ActionGenerator
is:Func<HedgingActionGeneratorArguments<TResult>, Func<ValueTask<Outcome<TResult>>>?>
Note the
?
inside the last>
brace.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
cc @tarekgh @ericstj