You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/05/11 15:44:50 UTC

groovy git commit: GROOVY-8055: @CompileStatic improperly orders parameter types

Repository: groovy
Updated Branches:
  refs/heads/master 5f6689638 -> 4bab03ae9


GROOVY-8055: @CompileStatic improperly orders parameter types


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

Branch: refs/heads/master
Commit: 4bab03ae95b1b69fc90dc32cb41f7a0687f8d277
Parents: 5f66896
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri May 11 23:44:49 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri May 11 23:44:49 2018 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          |  3 +-
 src/test/groovy/bugs/Groovy8055Bug.groovy       | 42 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4bab03ae/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 6d1f5eb..3ea9764 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -20,6 +20,7 @@
 package org.codehaus.groovy.transform.stc;
 
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.MethodNode;
@@ -956,7 +957,7 @@ public abstract class StaticTypeCheckingSupport {
             return dist;
         }
 
-        ClassNode ref = receiver;
+        ClassNode ref = isPrimitiveType(receiver) && !isPrimitiveType(compare) ? ClassHelper.getWrapper(receiver) : receiver;
         while (ref != null) {
             if (compare.equals(ref)) {
                 break;

http://git-wip-us.apache.org/repos/asf/groovy/blob/4bab03ae/src/test/groovy/bugs/Groovy8055Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8055Bug.groovy b/src/test/groovy/bugs/Groovy8055Bug.groovy
new file mode 100644
index 0000000..ca15c7e
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8055Bug.groovy
@@ -0,0 +1,42 @@
+/*
+ *  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 Groovy8055Bug extends GroovyTestCase {
+    void test1() {
+        assertScript '''
+        import groovy.transform.CompileStatic
+        
+        @CompileStatic
+        class Foo {
+            void isEqualTo(Number number) { println "Number"; assert true }
+            void isEqualTo(Object number) { println "Object"; assert false: 'wrong method invoked' }
+        }
+        
+        @CompileStatic
+        class Runner {
+            void run() {
+                new Foo().isEqualTo(4)
+            }
+        }
+        
+        new Runner().run()
+        '''
+    }
+}