groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject groovy git commit: GROOVY-7953: property expressions for extension methods on primitives fail STC (closes #442)
Date Sun, 09 Oct 2016 17:03:18 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 7285ffcfe -> 597a8d563


GROOVY-7953: property expressions for extension methods on primitives fail STC (closes #442)


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

Branch: refs/heads/master
Commit: 597a8d563a013763b6866b5ce6b30851e19b0941
Parents: 7285ffc
Author: Shil Sinha <shil.sinha@gmail.com>
Authored: Thu Oct 6 17:39:27 2016 -0400
Committer: Shil Sinha <shils@apache.org>
Committed: Sun Oct 9 12:32:19 2016 -0400

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          | 33 +++++++++++---------
 .../org.codehaus.groovy.runtime.ExtensionModule |  2 +-
 .../org.codehaus.groovy.runtime.ExtensionModule |  2 +-
 .../stc/STCExtensionMethodsTest.groovy          |  6 ++++
 .../sc/StaticCompileExtensionMethodsTest.groovy | 24 ++++++++++++++
 .../m12n/TestPrimitiveWrapperExtension.java     | 25 +++++++++++++++
 6 files changed, 76 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index df128eb..d5259b6 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1314,21 +1314,26 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                 }
             }
             // GROOVY-5568, the property may be defined by DGM
-            List<MethodNode> methods = findDGMMethodsByNameAndArguments(getTransformLoader(),
testClass, "get" + capName, ClassNode.EMPTY_ARRAY);
-            for (MethodNode m: findDGMMethodsByNameAndArguments(getTransformLoader(), testClass,
"is" + capName, ClassNode.EMPTY_ARRAY)) {
-                if (Boolean_TYPE.equals(getWrapper(m.getReturnType()))) methods.add(m);
-            }
-            if (!methods.isEmpty()) {
-                List<MethodNode> methodNodes = chooseBestMethod(testClass, methods,
ClassNode.EMPTY_ARRAY);
-                if (methodNodes.size() == 1) {
-                    MethodNode getter = methodNodes.get(0);
-                    if (visitor != null) {
-                        visitor.visitMethod(getter);
-                    }
-                    ClassNode cn = inferReturnTypeGenerics(testClass, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
-                    storeInferredTypeForPropertyExpression(pexp, cn);
+            List<ClassNode> dgmReceivers = new ArrayList<ClassNode>(2);
+            dgmReceivers.add(testClass);
+            if (isPrimitiveType(testClass)) dgmReceivers.add(getWrapper(testClass));
+            for (ClassNode dgmReceiver: dgmReceivers) {
+                List<MethodNode> methods = findDGMMethodsByNameAndArguments(getTransformLoader(),
dgmReceiver, "get" + capName, ClassNode.EMPTY_ARRAY);
+                for (MethodNode m : findDGMMethodsByNameAndArguments(getTransformLoader(),
dgmReceiver, "is" + capName, ClassNode.EMPTY_ARRAY)) {
+                    if (Boolean_TYPE.equals(getWrapper(m.getReturnType()))) methods.add(m);
+                }
+                if (!methods.isEmpty()) {
+                    List<MethodNode> methodNodes = chooseBestMethod(dgmReceiver, methods,
ClassNode.EMPTY_ARRAY);
+                    if (methodNodes.size() == 1) {
+                        MethodNode getter = methodNodes.get(0);
+                        if (visitor != null) {
+                            visitor.visitMethod(getter);
+                        }
+                        ClassNode cn = inferReturnTypeGenerics(dgmReceiver, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
+                        storeInferredTypeForPropertyExpression(pexp, cn);
 
-                    return true;
+                        return true;
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/spec/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
----------------------------------------------------------------------
diff --git a/src/spec/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
b/src/spec/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
index 67205e0..4926633 100644
--- a/src/spec/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
+++ b/src/spec/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
@@ -17,5 +17,5 @@
 # IT IS A WORKAROUND FOR 2 DESCRIPTORS ON CLASSPATH!
 moduleName=Test module
 moduleVersion=1.0-test
-extensionClasses=support.MaxRetriesExtension,org.codehaus.groovy.runtime.m12n.TestStringExtension,org.codehaus.groovy.runtime.m12n.Groovy6496Extension
+extensionClasses=support.MaxRetriesExtension,org.codehaus.groovy.runtime.m12n.TestStringExtension,org.codehaus.groovy.runtime.m12n.Groovy6496Extension,org.codehaus.groovy.runtime.m12n.TestPrimitiveWrapperExtension
 staticExtensionClasses=support.StaticStringExtension,org.codehaus.groovy.runtime.m12n.TestStaticStringExtension

http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
----------------------------------------------------------------------
diff --git a/src/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
b/src/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
index 69795a4..7287001 100644
--- a/src/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
+++ b/src/test-resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
@@ -16,5 +16,5 @@
 // This file is used to test the extension module framework
 moduleName=Test module
 moduleVersion=1.0-test
-extensionClasses=org.codehaus.groovy.runtime.m12n.TestStringExtension,org.codehaus.groovy.runtime.m12n.Groovy6496Extension
+extensionClasses=org.codehaus.groovy.runtime.m12n.TestStringExtension,org.codehaus.groovy.runtime.m12n.Groovy6496Extension,org.codehaus.groovy.runtime.m12n.TestPrimitiveWrapperExtension
 staticExtensionClasses=org.codehaus.groovy.runtime.m12n.TestStaticStringExtension

http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
index 3794f65..0af35a0 100644
--- a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
+++ b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
@@ -69,4 +69,10 @@ class STCExtensionMethodsTest extends StaticTypeCheckingTestCase {
             assert 2d.groovy6496(2d) == 2d
     '''
     }
+
+    void testExtensionPropertyWithPrimitiveReceiver() {
+        assertScript '''
+            assert 4.even
+        '''
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileExtensionMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileExtensionMethodsTest.groovy
b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileExtensionMethodsTest.groovy
new file mode 100644
index 0000000..426bba5
--- /dev/null
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileExtensionMethodsTest.groovy
@@ -0,0 +1,24 @@
+/*
+ *  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 org.codehaus.groovy.classgen.asm.sc
+
+import groovy.transform.stc.STCExtensionMethodsTest
+
+class StaticCompileExtensionMethodsTest extends STCExtensionMethodsTest implements StaticCompilationTestSupport
{
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/597a8d56/src/test/org/codehaus/groovy/runtime/m12n/TestPrimitiveWrapperExtension.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/TestPrimitiveWrapperExtension.java
b/src/test/org/codehaus/groovy/runtime/m12n/TestPrimitiveWrapperExtension.java
new file mode 100644
index 0000000..1617f92
--- /dev/null
+++ b/src/test/org/codehaus/groovy/runtime/m12n/TestPrimitiveWrapperExtension.java
@@ -0,0 +1,25 @@
+/*
+ *  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 org.codehaus.groovy.runtime.m12n;
+
+public class TestPrimitiveWrapperExtension {
+    public static boolean isEven(Integer self) {
+        return self % 2 == 0;
+    }
+}


Mime
View raw message