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-7924: groovyc fails with NPE for dynamic method/property use on super (closes #407)
Date Thu, 01 Sep 2016 22:42:39 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 7e8211fa3 -> bdcda17ec


GROOVY-7924: groovyc fails with NPE for dynamic method/property use on super (closes #407)


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

Branch: refs/heads/master
Commit: bdcda17ec3c0eb983c5492323db6ca2b2f331146
Parents: 7e8211f
Author: paulk <paulk@asert.com.au>
Authored: Thu Sep 1 22:50:16 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Fri Sep 2 08:42:23 2016 +1000

----------------------------------------------------------------------
 .../groovy/classgen/AsmClassGenerator.java      | 20 ++++-----
 src/test/groovy/bugs/Groovy7924Bug.groovy       | 43 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/bdcda17e/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
index b169761..30a49e0 100644
--- a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -917,17 +917,17 @@ public class AsmClassGenerator extends ClassGenerator {
                     visitFieldExpression(new FieldExpression(field));
                     return;
                 }
-            }
-            if (isSuperExpression(objectExpression)) {
-                String prefix;
-                if (controller.getCompileStack().isLHS()) {
-                    throw new GroovyBugError("Unexpected super property set for:"+expression.getText());
-                } else {
-                    prefix = "get";
+                if (isSuperExpression(objectExpression)) {
+                    String prefix;
+                    if (controller.getCompileStack().isLHS()) {
+                        throw new GroovyBugError("Unexpected super property set for:" + expression.getText());
+                    } else {
+                        prefix = "get";
+                    }
+                    String propName = prefix + MetaClassHelper.capitalize(name);
+                    visitMethodCallExpression(new MethodCallExpression(objectExpression,
propName, MethodCallExpression.NO_ARGUMENTS));
+                    return;
                 }
-                String propName = prefix + MetaClassHelper.capitalize(name);
-                visitMethodCallExpression(new MethodCallExpression(objectExpression, propName,
MethodCallExpression.NO_ARGUMENTS));
-                return;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/bdcda17e/src/test/groovy/bugs/Groovy7924Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7924Bug.groovy b/src/test/groovy/bugs/Groovy7924Bug.groovy
new file mode 100644
index 0000000..4c33c22
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7924Bug.groovy
@@ -0,0 +1,43 @@
+/*
+ *  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
+
+class Groovy7924Bug extends GroovyTestCase {
+    void testShouldBeAbleToAssignThisInsideCategoryAnnotatedClass() {
+        assertScript '''
+            class Base {
+                def foo = 'oof'
+                def bar() { 'rab' }
+            }
+
+            class Child extends Base {
+                def superAccess(name) { super."$name" }
+                def superInvoke(name) { super."$name"() }
+                def thisAccess(name) { this."$name" }
+                def thisInvoke(name) { this."$name"() }
+            }
+
+            def c = new Child()
+            assert c.thisAccess('foo') == 'oof'
+            assert c.thisInvoke('bar') == 'rab'
+            assert c.superAccess('foo') == 'oof'
+            assert c.superInvoke('bar') == 'rab'
+        '''
+    }
+}


Mime
View raw message