Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GROOVY-5655: Fix vargs test for constructor calls

  • Loading branch information...
commit be0bf7ade628ce1c9edd42901ef99ed6e6320ae6 1 parent b7ef54b
@melix melix authored
View
8 src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -201,9 +201,14 @@ protected void loadArguments(List<Expression> argumentList, Parameter[] para) {
if (para.length == 0) return;
ClassNode lastParaType = para[para.length - 1].getOriginType();
AsmClassGenerator acg = controller.getAcg();
+ TypeChooser typeChooser = controller.getTypeChooser();
OperandStack operandStack = controller.getOperandStack();
+ ClassNode lastArgType = argumentList.size()>0?
+ typeChooser.resolveType(argumentList.get(argumentList.size()-1), controller.getClassNode()):null;
if (lastParaType.isArray()
- && (argumentList.size() > para.length || argumentList.size() == para.length - 1 || !argumentList.get(para.length - 1).getType().isArray())) {
+ && (argumentList.size() > para.length
+ || (argumentList.size() == para.length - 1 && !lastParaType.equals(lastArgType)))
+ ) {
int stackLen = operandStack.getStackLength() + argumentList.size();
MethodVisitor mv = controller.getMethodVisitor();
MethodVisitor orig = mv;
@@ -245,7 +250,6 @@ protected void loadArguments(List<Expression> argumentList, Parameter[] para) {
}
} else {
// method call with default arguments
- TypeChooser typeChooser = controller.getTypeChooser();
ClassNode classNode = controller.getClassNode();
Expression[] arguments = new Expression[para.length];
for (int i = 0, j = 0; i < para.length; i++) {
View
11 src/test/org/codehaus/groovy/classgen/asm/sc/TypeInferenceStaticCompileTest.groovy
@@ -30,5 +30,16 @@ class TypeInferenceStaticCompileTest extends TypeInferenceSTCTest {
super.setUp()
extraSetup()
}
+
+ // GROOVY-5655
+ void testByteArrayInference() {
+ assertScript '''
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
+ assert node.getNodeMetaData(INFERRED_TYPE) == byte_TYPE.makeArray()
+ })
+ def b = "foo".bytes
+ new String(b)
+ '''
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.