From 2d189dc93c8af9c941b316a829b68b8ab3fbce10 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 22 Nov 2016 17:01:15 +0100 Subject: [PATCH] [mcs] Null coalescing over typed null constants. --- mcs/mcs/nullable.cs | 2 +- mcs/tests/gtest-621.cs | 6 ++++++ mcs/tests/ver-il-net_4_x.xml | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mcs/mcs/nullable.cs b/mcs/mcs/nullable.cs index cce1f8419ce..93314df322a 100644 --- a/mcs/mcs/nullable.cs +++ b/mcs/mcs/nullable.cs @@ -1210,7 +1210,7 @@ namespace Mono.CSharp.Nullable // // Special case null ?? null // - if (right.IsNull && ltype == right.Type) + if (right is NullLiteral && ltype == right.Type) return null; return ReducedExpression.Create (lc != null ? right : left, this, false); diff --git a/mcs/tests/gtest-621.cs b/mcs/tests/gtest-621.cs index cfff301328e..6444cb7918e 100644 --- a/mcs/tests/gtest-621.cs +++ b/mcs/tests/gtest-621.cs @@ -26,4 +26,10 @@ class X return 0; } + + const Action cf = null; + void Foo (Action f) + { + var x = f ?? cf; + } } \ 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 ddb13732d04..4502b9b63be 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -19564,6 +19564,9 @@ 7 + + 4 + -- 2.25.1