[mcs] Recursivelly check for left-hand side of an assignment of a null propagating...
authorMarek Safar <marek.safar@gmail.com>
Wed, 3 Jun 2015 10:01:24 +0000 (12:01 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 3 Jun 2015 10:04:51 +0000 (12:04 +0200)
mcs/errors/cs9030-2.cs [new file with mode: 0644]
mcs/mcs/ecore.cs
mcs/mcs/expression.cs

diff --git a/mcs/errors/cs9030-2.cs b/mcs/errors/cs9030-2.cs
new file mode 100644 (file)
index 0000000..c7d6fcc
--- /dev/null
@@ -0,0 +1,17 @@
+// CS9030: The left-hand side of an assignment cannot contain a null propagating operator
+// Line: 15
+
+public class Test1
+{
+       public class Test2
+       {
+               public System.EventHandler<System.EventArgs> E;
+       }
+
+       public Test2 test2 = new Test2 ();
+
+       static void Main ()
+       {
+               new Test1 ()?.test2.E += null;
+       }
+}
index f1723d2352a868dbdc1e6f016fa884b9516d67c7..74501e89b1503db64ab68fca1a7a884ba1632867 100644 (file)
@@ -6385,7 +6385,7 @@ namespace Mono.CSharp {
 
                public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
                {
-                       if (ConditionalAccess)
+                       if (HasConditionalAccess ())
                                Error_NullPropagatingLValue (ec);
 
                        if (spec is FixedFieldSpec) {
@@ -7144,7 +7144,7 @@ namespace Mono.CSharp {
 
                public override Expression DoResolveLValue (ResolveContext rc, Expression right_side)
                {
-                       if (ConditionalAccess)
+                       if (HasConditionalAccess ())
                                Error_NullPropagatingLValue (rc);
 
                        if (right_side == EmptyExpression.OutAccess) {
@@ -7390,7 +7390,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (ConditionalAccess)
+                       if (HasConditionalAccess ())
                                Error_NullPropagatingLValue (ec);
 
                        op = CandidateToBaseOverride (ec, op);
index 998b2f2afaf104b500022c67732fe08f1464e0a2..5f6c0633727978265700c2e19e9e9df2f82b839e 100644 (file)
@@ -10374,7 +10374,7 @@ namespace Mono.CSharp
 
                public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
                {
-                       if (ConditionalAccess)
+                       if (HasConditionalAccess ())
                                Error_NullPropagatingLValue (ec);
 
                        return DoResolve (ec);