Skip to content

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

Merged
merged 4 commits into from
Jul 31, 2023
Merged

Conversation

captainsafia
Copy link
Member

@ghost ghost added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels area-runtime labels Jul 27, 2023
@captainsafia captainsafia added feature-rdg area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jul 27, 2023
@captainsafia captainsafia marked this pull request as ready for review July 28, 2023 00:21
@captainsafia captainsafia requested a review from mitchdenny July 28, 2023 00:21
EndpointParameterSource.BindAsync => endpointParameter.IsOptional ?
endpointParameter.EmitHandlerArgument() :
endpointParameter.Type.IsValueType && endpointParameter.GetBindAsyncReturnType()?.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T
? $"{endpointParameter.EmitHandlerArgument()}.Value"
Copy link
Member

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.

Copy link
Member Author

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.

@captainsafia captainsafia force-pushed the safia/minapi-playground-bug-fixes branch from b161f5e to 69dae0a Compare July 30, 2023 05:03
@captainsafia captainsafia force-pushed the safia/minapi-playground-bug-fixes branch from 69dae0a to fa6c6d6 Compare July 30, 2023 20:36
codeWriter.WriteLine($"if ((object?){endpointParameter.EmitTempArgument()} == null)");
codeWriter.WriteLine(endpointParameter.Type.IsValueType && endpointParameter.GetBindAsyncReturnType().IsNullableOfT()
? $"if (!{endpointParameter.EmitHandlerArgument()}.HasValue)"
: $"if ({endpointParameter.EmitHandlerArgument()} == null)");
Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

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.

@captainsafia captainsafia merged commit 0a74dff into main Jul 31, 2023
@captainsafia captainsafia deleted the safia/minapi-playground-bug-fixes branch July 31, 2023 20:51
@ghost ghost added this to the 8.0-rc1 milestone Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RDG doesn't support BindAsync result with differing nullability
2 participants