-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix BindAsync and misc bugs in RDG #49693
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
Conversation
EndpointParameterSource.BindAsync => endpointParameter.IsOptional ? | ||
endpointParameter.EmitHandlerArgument() : | ||
endpointParameter.Type.IsValueType && endpointParameter.GetBindAsyncReturnType()?.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T | ||
? $"{endpointParameter.EmitHandlerArgument()}.Value" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be guarded? A user could write return null!;
and then get an InvalidOperationException in our code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! I fixed this bug for RDG and added a test (MapAction_BindAsync_NullableReturn
).
Turns out the same bug for structs exists in RDF. I haven't fixed it here but I've filed #49730 to track it.
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Emitter.cs
Show resolved
Hide resolved
...xtensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
...xtensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
b161f5e
to
69dae0a
Compare
69dae0a
to
fa6c6d6
Compare
codeWriter.WriteLine($"if ((object?){endpointParameter.EmitTempArgument()} == null)"); | ||
codeWriter.WriteLine(endpointParameter.Type.IsValueType && endpointParameter.GetBindAsyncReturnType().IsNullableOfT() | ||
? $"if (!{endpointParameter.EmitHandlerArgument()}.HasValue)" | ||
: $"if ({endpointParameter.EmitHandlerArgument()} == null)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (ValueType == null)
will result in a warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpointParameter.GetBindAsyncReturnType().IsNullableOfT()
GetBindAsyncReturnType
can return null, why isn't the compiler complaining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetBindAsyncReturnType can return null, why isn't the compiler complaining?
IsNullableOfT
takes a ITypeSymbol?
and does a null safety check in its implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eww 😆
@@ -643,8 +609,7 @@ namespace Microsoft.AspNetCore.Http.Generated | |||
async Task RequestHandler(HttpContext httpContext) | |||
{ | |||
var wasParamCheckFailure = false; | |||
var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); | |||
var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct?)myBindAsyncParam_temp; | |||
var myBindAsyncParam_local = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); | |||
|
|||
if (wasParamCheckFailure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Unused code. Looks like it was here before the PR though.
Error
toWarning
for fallback scenariosEndpointParameterMetadataProvider
was not respected if parameters that didn't implement the interface existed on an endpointBindAsync
handling to resolve RDG doesn't supportBindAsync
result with differing nullability #47199