You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/12/16 22:53:43 UTC
groovy git commit: GROOVY-7420: Prefer a method signature without
boxing or unboxing (closes #204)
Repository: groovy
Updated Branches:
refs/heads/master 8bb350a98 -> c90de50c4
GROOVY-7420: Prefer a method signature without boxing or unboxing (closes #204)
The method resolution mechanism is closer to what is done when following the
Java Language Specification (JLS 15.2.2), and removes the ambiguity when
calling a method having both primitive- and object-parameter overloads with
an object argument.
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c90de50c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c90de50c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c90de50c
Branch: refs/heads/master
Commit: c90de50c412423829f9abaa2489166d72cefa2af
Parents: 8bb350a
Author: Frank Pavageau <fp...@ekino.com>
Authored: Wed Dec 16 10:05:20 2015 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Wed Dec 16 22:52:49 2015 +0100
----------------------------------------------------------------------
.../groovy/transform/stc/StaticTypeCheckingSupport.java | 4 +++-
.../codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy | 5 +++--
2 files changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/c90de50c/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 4760cb3..eb6bac9 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -816,7 +816,9 @@ public abstract class StaticTypeCheckingSupport {
&& unwrapReceiver!=unwrapCompare) {
dist = getPrimitiveDistance(unwrapReceiver, unwrapCompare);
}
- if (isPrimitiveType(receiver) && !isPrimitiveType(compare)) {
+ // Add a penalty against boxing or unboxing, to get a resolution similar to JLS 15.12.2
+ // (http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2).
+ if (isPrimitiveType(receiver) ^ isPrimitiveType(compare)) {
dist = (dist+1)<<1;
}
if (unwrapCompare.equals(unwrapReceiver)) return dist;
http://git-wip-us.apache.org/repos/asf/groovy/blob/c90de50c/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy
index 82642e1..5205ee0 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7420Bug.groovy
@@ -18,12 +18,10 @@
*/
package org.codehaus.groovy.classgen.asm.sc.bugs
-import groovy.transform.NotYetImplemented
import groovy.transform.stc.StaticTypeCheckingTestCase
import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
class Groovy7420Bug extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
- @NotYetImplemented
void testOverloadedMethodWithPrimitiveOrObjectParameter() {
assertScript '''
class A {
@@ -38,6 +36,9 @@ class Groovy7420Bug extends StaticTypeCheckingTestCase implements StaticCompilat
Long l = 42L
assert A.m(l) == "object"
+ assert A.m(l.longValue()) == "primitive"
+ int i = 42
+ assert A.m(i) == "primitive" // Primitive widening
'''
}
}