Skip to content

Commit b691656

Browse files
committed
[mcs] Better recovery from failed async return type inference. Fixes #25165
1 parent 72c52fe commit b691656

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

mcs/errors/cs0126-3.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// CS0126: An object of a type convertible to `int' is required for the return statement
2+
// Line: 15
3+
4+
using System.Threading.Tasks;
5+
6+
class MainClass
7+
{
8+
public static void Main ()
9+
{
10+
Task<C> v = null;
11+
12+
Task.Run (async () => {
13+
await Task.Yield ();
14+
if (v == null) {
15+
return;
16+
}
17+
18+
return 1;
19+
});
20+
}
21+
}
22+
23+
public class C
24+
{
25+
string Id { get; set; }
26+
}

mcs/mcs/statement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ protected override bool DoResolve (BlockContext ec)
11351135
var block_return_type = ec.ReturnType;
11361136

11371137
if (expr == null) {
1138-
if (block_return_type.Kind == MemberKind.Void)
1138+
if (block_return_type.Kind == MemberKind.Void || block_return_type == InternalType.ErrorType)
11391139
return true;
11401140

11411141
//

0 commit comments

Comments
 (0)