Skip to content
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

Allow overriding the AsyncMethodBuilder on methods #54033

Merged
merged 28 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78a89b7
Allow AsyncMethodBuilder on method
jcouv Jun 7, 2021
f084cb2
Allow returning a non-task-like type
jcouv Jun 15, 2021
e1f1d41
Relax accessibility requirements for overrides
jcouv Jun 15, 2021
a39ee15
Factor extension methods
jcouv Jun 16, 2021
e4ab3c3
Fix nullability scenario
jcouv Jun 16, 2021
72cbc01
Fix lambda scenario with non-task-like return type
jcouv Jun 17, 2021
3e9518b
Fix test
jcouv Jun 17, 2021
2a3fdf1
Disallow non-task-like return type after all
jcouv Jun 17, 2021
869671b
Validate ignored builder type
jcouv Jun 18, 2021
22b5373
use TryCreate
jcouv Jun 18, 2021
8ac378a
Merge remote-tracking branch 'dotnet/main' into async-builder
jcouv Jun 18, 2021
2e7ad79
hasErros
jcouv Jun 21, 2021
4375aea
Factor extension method
jcouv Jun 21, 2021
43416a2
using
jcouv Jun 21, 2021
d5c0a27
Revert "Disallow non-task-like return type after all"
jcouv Jun 21, 2021
f7900d8
Revert "Validate ignored builder type"
jcouv Jun 21, 2021
e7ed4e3
Restore tests
jcouv Jun 21, 2021
af160e2
Remove validation on return type
jcouv Jun 21, 2021
4218507
Remove builder/factory indirection
jcouv Jun 21, 2021
ee207cb
tweaks
jcouv Jun 21, 2021
ec32fb2
Address feedback
jcouv Jun 22, 2021
9637282
Merge commit '9bcaddccfefc7d8e1804440419c17806e9ac9f27' into async-bu…
jcouv Jun 22, 2021
7da7da7
Integrate explicit return types and builder overrides
jcouv Jun 22, 2021
457aac7
Merge remote-tracking branch 'dotnet/main' into async-builder
jcouv Jun 22, 2021
3268386
Merge remote-tracking branch 'dotnet/main' into async-builder
jcouv Jun 22, 2021
9440d0f
Adjust error code in tests
jcouv Jun 23, 2021
a576b8c
Address feedback
jcouv Jun 23, 2021
36b5a5d
typo
jcouv Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8597,8 +8597,7 @@ private bool ContainingMethodOrLambdaRequiresValue()
return
(object)containingMethod == null ||
!containingMethod.ReturnsVoid &&
!containingMethod.IsAsyncReturningTask(this.Compilation) &&
!containingMethod.IsAsyncReturningTaskViaOverride(out _);
!containingMethod.IsAsyncReturningTask(this.Compilation);
}

private BoundConditionalAccess GenerateBadConditionalAccessNodeError(ConditionalAccessExpressionSyntax node, BoundExpression receiver, BoundExpression access, BindingDiagnosticBag diagnostics)
Expand Down
25 changes: 6 additions & 19 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ BoundBlock runAnalysis(BoundBlock block, BindingDiagnosticBag blockDiagnostics)

private bool ImplicitReturnIsOkay(MethodSymbol method)
{
return method.ReturnsVoid || method.IsIterator || method.IsAsyncReturningTask(this.Compilation) || method.IsAsyncReturningTaskViaOverride(out _);
return method.ReturnsVoid || method.IsIterator || method.IsAsyncReturningTask(this.Compilation);
}

public BoundStatement BindExpressionStatement(ExpressionStatementSyntax node, BindingDiagnosticBag diagnostics)
Expand Down Expand Up @@ -2650,24 +2650,12 @@ protected bool IsTaskReturningAsyncMethod()
return symbol?.Kind == SymbolKind.Method && ((MethodSymbol)symbol).IsAsyncReturningTask(this.Compilation);
}

protected bool IsTaskReturningAsyncMethodViaOverride()
{
var symbol = this.ContainingMemberOrLambda;
return symbol?.Kind == SymbolKind.Method && ((MethodSymbol)symbol).IsAsyncReturningTaskViaOverride(out _);
}

protected bool IsGenericTaskReturningAsyncMethod()
{
var symbol = this.ContainingMemberOrLambda;
return symbol?.Kind == SymbolKind.Method && ((MethodSymbol)symbol).IsAsyncReturningGenericTask(this.Compilation);
}

protected bool IsGenericTaskReturningAsyncMethodViaOverride()
{
var symbol = this.ContainingMemberOrLambda;
return symbol?.Kind == SymbolKind.Method && ((MethodSymbol)symbol).IsAsyncReturningGenericTaskViaOverride(out _);
}

protected bool IsIAsyncEnumerableOrIAsyncEnumeratorReturningAsyncMethod()
{
var symbol = this.ContainingMemberOrLambda;
Expand Down Expand Up @@ -2768,7 +2756,7 @@ private BoundStatement BindReturn(ReturnStatementSyntax syntax, BindingDiagnosti
// on a lambda expression of unknown return type.
if ((object)retType != null)
{
if (retType.IsVoidType() || IsTaskReturningAsyncMethod() || IsTaskReturningAsyncMethodViaOverride())
if (retType.IsVoidType() || IsTaskReturningAsyncMethod())
{
if (arg != null)
{
Expand Down Expand Up @@ -2808,7 +2796,7 @@ private BoundStatement BindReturn(ReturnStatementSyntax syntax, BindingDiagnosti
if (arg == null)
{
// Error case: non-void-returning or Task<T>-returning method or lambda but just have "return;"
var requiredType = IsGenericTaskReturningAsyncMethod() || IsGenericTaskReturningAsyncMethodViaOverride()
var requiredType = IsGenericTaskReturningAsyncMethod()
? retType.GetMemberTypeArgumentsNoUseSiteDiagnostics().Single()
: retType;

Expand Down Expand Up @@ -2851,7 +2839,7 @@ internal BoundExpression CreateReturnConversion(
{
Debug.Assert(returnRefKind == RefKind.None);

if (!IsGenericTaskReturningAsyncMethod() && !IsGenericTaskReturningAsyncMethodViaOverride())
if (!IsGenericTaskReturningAsyncMethod())
{
conversion = Conversion.NoConversion;
badAsyncReturnAlreadyReported = true;
Expand Down Expand Up @@ -2888,8 +2876,7 @@ internal BoundExpression CreateReturnConversion(
if (!badAsyncReturnAlreadyReported)
{
RefKind unusedRefKind;
if ((IsGenericTaskReturningAsyncMethod() || IsGenericTaskReturningAsyncMethodViaOverride())
&& TypeSymbol.Equals(argument.Type, this.GetCurrentReturnType(out unusedRefKind), TypeCompareKind.ConsiderEverything2))
if (IsGenericTaskReturningAsyncMethod() && TypeSymbol.Equals(argument.Type, this.GetCurrentReturnType(out unusedRefKind), TypeCompareKind.ConsiderEverything2))
{
// Since this is an async method, the return expression must be of type '{0}' rather than 'Task<{0}>'
Error(diagnostics, ErrorCode.ERR_BadAsyncReturnExpression, argument.Syntax, returnType);
Expand Down Expand Up @@ -3178,7 +3165,7 @@ internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableAr
expression = BindToTypeForErrorRecovery(expression);
statement = new BoundReturnStatement(syntax, RefKind.None, expression) { WasCompilerGenerated = true };
}
else if (returnType.IsVoidType() || IsTaskReturningAsyncMethod() || IsTaskReturningAsyncMethodViaOverride())
else if (returnType.IsVoidType() || IsTaskReturningAsyncMethod())
{
// If the return type is void then the expression is required to be a legal
// statement expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static BoundBlock Rewrite(
#endif
var compilation = method.DeclaringCompilation;

if (method.ReturnsVoid || method.IsIterator || method.IsAsyncReturningTask(compilation) || method.IsAsyncReturningTaskViaOverride(out _))
if (method.ReturnsVoid || method.IsIterator || method.IsAsyncReturningTask(compilation))
{
// we don't analyze synthesized void methods.
if ((method.IsImplicitlyDeclared && !method.IsScriptInitializer) ||
Expand Down
Loading