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 2019/11/11 05:59:21 UTC
[groovy] 07/09: use redirect for reference comparison
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit db4bb8060bf8e3af21fb63f8837a93056d59d60e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Nov 10 19:59:04 2019 -0600
use redirect for reference comparison
---
.../java/org/codehaus/groovy/ast/ClassHelper.java | 2 ++
.../classgen/asm/sc/BugsStaticCompileTest.groovy | 33 ++++++++++++++++++++--
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index c71f786..b5f7fac 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -364,6 +364,7 @@ public class ClassHelper {
* @see #make(String)
*/
public static boolean isStaticConstantInitializerType(ClassNode cn) {
+ cn = cn.redirect();
return cn == int_TYPE ||
cn == float_TYPE ||
cn == long_TYPE ||
@@ -376,6 +377,7 @@ public class ClassHelper {
}
public static boolean isNumberType(ClassNode cn) {
+ cn = cn.redirect();
return cn == Byte_TYPE ||
cn == Short_TYPE ||
cn == Integer_TYPE ||
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 66eda6c..ce29a78 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -196,7 +196,7 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
@groovy.transform.CompileStatic
class Main {
void test() {
- @ASTTest(phase=INSTRUCTION_SELECTION, value= {
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.rightExpression.getNodeMetaData(INFERRED_TYPE).nameWithoutPackage == 'Sql'
})
def sql = Sql.newInstance("a", "b", "c", "d")
@@ -720,7 +720,7 @@ import groovy.transform.TypeCheckingMode
shouldFailWithMessages '''
def fieldMatcher = '[x=1] [a=b] [foo=bar]' =~ ~"\\\\[([^=\\\\[]+)=([^\\\\]]+)\\\\]"
assert fieldMatcher instanceof java.util.regex.Matcher
- @ASTTest(phase=INSTRUCTION_SELECTION, value = {
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.getNodeMetaData(INFERRED_TYPE) == OBJECT_TYPE
})
def value = fieldMatcher[0]
@@ -1470,7 +1470,6 @@ println someInt
assertScript '''
import static java.nio.file.AccessMode.*
- @groovy.transform.CompileStatic
class Dummy {
static main() {
// more than 5 to match `of(E first, E[] rest)` variant
@@ -1481,4 +1480,32 @@ println someInt
assert Dummy.main() == [READ, WRITE, EXECUTE].toSet()
'''
}
+
+ void testNumberWrapperMultiAssign() {
+ assertScript '''
+ import org.codehaus.groovy.ast.CodeVisitorSupport
+ import org.codehaus.groovy.ast.expr.ConstantExpression
+
+ void test() {
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
+ node.visit(new CodeVisitorSupport() {
+ @Override
+ void visitConstantExpression(ConstantExpression expr) {
+ switch (expr.text) {
+ case '123':
+ case '456':
+ assert ClassHelper.isNumberType(expr.type)
+ break
+ default:
+ assert false : "unexpected constant: $expr"
+ }
+ }
+ })
+ })
+ def (Integer i, Long j) = [123, 456L]
+ }
+
+ test()
+ '''
+ }
}