未验证 提交 67d75c04 编写于 作者: C Charles Stoner 提交者: GitHub

Use signature return type to determine task type in NullableWalker (#37488)

上级 a0009846
......@@ -1520,7 +1520,7 @@ private void EmitCallExpression(BoundCall call, UseKind useKind)
// otherwise we should not use direct 'call' and must use constrained call;
// calling a method defined in a value type
Debug.Assert(TypeSymbol.Equals(receiverType, methodContainingType, TypeCompareKind.ConsiderEverything2));
Debug.Assert(TypeSymbol.Equals(receiverType, methodContainingType, TypeCompareKind.ObliviousNullableModifierMatchesAny));
tempOpt = EmitReceiverRef(receiver, receiverAddresskind);
callKind = CallKind.Call;
}
......
......@@ -1419,7 +1419,7 @@ private bool TryGetReturnType(out TypeWithAnnotations type)
return true;
}
if (method.IsGenericTaskReturningAsync(compilation))
if (returnType.Type.IsGenericTaskType(compilation))
{
type = ((NamedTypeSymbol)returnType.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single();
return true;
......
......@@ -113357,5 +113357,64 @@ public interface IEquatable<T>
", options: WithNonNullTypesTrue().WithSpecificDiagnosticOptions("CS0436", ReportDiagnostic.Suppress));
comp.VerifyDiagnostics();
}
[Fact]
[WorkItem(37269, "https://github.com/dotnet/roslyn/issues/37269")]
public void TypeParameterReturnType_01()
{
var source =
@"using System;
using System.Threading.Tasks;
static class ResultExtensions
{
static async Task<Result<TResult, B>> MapAsync<A, B, TResult>(
this Result<A, B> result,
Func<A, Task<TResult>> map)
{
return await result.Match(
async a => FromA<TResult>(await map(a)),
b => Task.FromResult(FromB<TResult, B>(b)));
}
static Result<A, B> FromA<A, B>(A value) => throw null!;
static Result<A, B> FromB<A, B>(B value) => throw null!;
}
class Result<A, B>
{
public TResult Match<TResult>(Func<A, TResult> a, Func<B, TResult> b) => throw null!;
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (10,24): error CS0305: Using the generic method 'ResultExtensions.FromA<A, B>(A)' requires 2 type arguments
// async a => FromA<TResult>(await map(a)),
Diagnostic(ErrorCode.ERR_BadArity, "FromA<TResult>").WithArguments("ResultExtensions.FromA<A, B>(A)", "method", "2").WithLocation(10, 24));
}
[Fact]
public void TypeParameterReturnType_02()
{
var source =
@"using System;
using System.Threading.Tasks;
static class ResultExtensions
{
static async Task<Result<TResult, B>> MapAsync<A, B, TResult>(
this Result<A, B> result,
Func<A, Task<TResult>> map)
{
return await result.Match(
async a => FromA<TResult, B>(await map(a)),
b => Task.FromResult(FromB<TResult, B>(b)));
}
static Result<A, B> FromA<A, B>(A value) => throw null!;
static Result<A, B> FromB<A, B>(B value) => throw null!;
}
class Result<A, B>
{
public TResult Match<TResult>(Func<A, TResult> a, Func<B, TResult> b) => throw null!;
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
// Use VerifyEmitDiagnostics() to test assertions in CodeGenerator.EmitCallExpression.
comp.VerifyEmitDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册