groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-7925: 'this' and 'super' as LHS of an assignment
Date Sun, 11 Sep 2016 22:29:29 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 7e19592c1 -> ff5dcf640


GROOVY-7925: 'this' and 'super' as LHS of an assignment


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/ff5dcf64
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ff5dcf64
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ff5dcf64

Branch: refs/heads/GROOVY_2_4_X
Commit: ff5dcf6402365d6be947a88215bb18578fc7d1b9
Parents: 7e19592
Author: paulk <paulk@asert.com.au>
Authored: Sun Sep 4 22:35:54 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Mon Sep 12 08:29:15 2016 +1000

----------------------------------------------------------------------
 .../classgen/ClassCompletionVerifier.java       | 11 +++++++
 src/test/groovy/bugs/Groovy7925Bug.groovy       | 32 ++++++++++++++++++++
 2 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ff5dcf64/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
index 9fe13cf..c01efdc 100644
--- a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
+++ b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
@@ -520,12 +520,23 @@ public class ClassCompletionVerifier extends ClassCodeVisitorSupport
{
             case Types.RIGHT_SHIFT_EQUAL:
             case Types.RIGHT_SHIFT_UNSIGNED_EQUAL:
                 checkFinalFieldAccess(expression.getLeftExpression());
+                checkSuperOrThisOnLHS(expression.getLeftExpression());
                 break;
             default:
                 break;
         }
     }
 
+    private void checkSuperOrThisOnLHS(Expression expression) {
+        if (!(expression instanceof VariableExpression)) return;
+        VariableExpression ve = (VariableExpression) expression;
+        if (ve.isThisExpression()) {
+            addError("cannot have 'this' as LHS of an assignment", expression);
+        } else if (ve.isSuperExpression()) {
+            addError("cannot have 'super' as LHS of an assignment", expression);
+        }
+    }
+
     private void checkFinalFieldAccess(Expression expression) {
         if (!(expression instanceof VariableExpression) && !(expression instanceof
PropertyExpression)) return;
         Variable v = null;

http://git-wip-us.apache.org/repos/asf/groovy/blob/ff5dcf64/src/test/groovy/bugs/Groovy7925Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7925Bug.groovy b/src/test/groovy/bugs/Groovy7925Bug.groovy
new file mode 100644
index 0000000..f932135
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7925Bug.groovy
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import gls.CompilableTestSupport
+
+class Groovy7925Bug extends CompilableTestSupport {
+    void testThisAndSuperOnLHS() {
+        def message = shouldNotCompile '''
+            super += true
+            this = false
+        '''
+        assert message.contains("cannot have 'this' as LHS of an assignment")
+        assert message.contains("cannot have 'super' as LHS of an assignment")
+    }
+}


Mime
View raw message