From 15082972b9678df3408fc607551cab2978f1a661 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Mon, 7 Mar 2016 21:00:08 +0100 Subject: [PATCH] [mcs] Null conditional operator is never suppose to work with await according to current C# standard. Fixes #39266 --- mcs/mcs/async.cs | 6 ++- mcs/tests/test-async-83.cs | 34 +++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 74 ++++++++++++++++++------------------ 3 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 mcs/tests/test-async-83.cs diff --git a/mcs/mcs/async.cs b/mcs/mcs/async.cs index 22e4c1b4b8c..b3efae32410 100644 --- a/mcs/mcs/async.cs +++ b/mcs/mcs/async.cs @@ -349,7 +349,11 @@ namespace Mono.CSharp var errors_printer = new SessionReportPrinter (); var old = bc.Report.SetPrinter (errors_printer); - ama = new Invocation (ama, args).Resolve (bc); + + // + // The expression await t is classified the same way as the expression (t).GetAwaiter().GetResult(). + // + ama = new Invocation (new ParenthesizedExpression (ama, Location.Null), args).Resolve (bc); bc.Report.SetPrinter (old); if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression (ama.Type)) { diff --git a/mcs/tests/test-async-83.cs b/mcs/tests/test-async-83.cs new file mode 100644 index 00000000000..b12dd20fa74 --- /dev/null +++ b/mcs/tests/test-async-83.cs @@ -0,0 +1,34 @@ +using System; +using System.Threading.Tasks; + +class MainClass +{ + public static int Main () + { + var t = GetSomeStrings (null); + try { + var s = t.Result; + return 1; + } catch (AggregateException e) { + if (e.InnerException is NullReferenceException) + return 0; + + return 2; + } + } + + public static async Task GetSomeStrings (AsyncStringFactory myFactory) + { + var res = await myFactory?.GetSomeStringAsync (); + return res; + } +} + +public class AsyncStringFactory +{ + public async Task GetSomeStringAsync () + { + await Task.Yield(); + return "foo"; + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 702908fa939..b3846fd0d97 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -62865,43 +62865,6 @@ - - - - 35 - - - 96 - - - 29 - - - 7 - - - 12 - - - - - 227 - - - - - 29 - - - 7 - - - - - 13 - - - @@ -65651,6 +65614,43 @@ + + + + 57 + + + 41 + + + 7 + + + + + 33 + + + 7 + + + + + 191 + + + 13 + + + + + 171 + + + 13 + + + -- 2.25.1