Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ public void evaluateEqual(final BinaryExpression expression, final boolean defin
return;
}

// GROOVY-11959: box primitive RHS so the temp slot holds an object reference
// (the multi-assignment path ALOADs it for IF_ACMPEQ and dispatches iterator/getAt on it)
if (!singleAssignment && ClassHelper.isPrimitiveType(rhsType)) {
operandStack.box();
rhsType = operandStack.getTopOperand();
}

int rhsValueId = compileStack.defineTemporaryVariable("$rhs", rhsType, true);
// TODO: if RHS is already a VariableSlotLoader, then skip creating a new one
Expression rhsValueLoader = new VariableSlotLoader(rhsType, rhsValueId, operandStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ final class MultipleAssignmentDeclarationTest {
'''
}

@Test // GROOVY-11959
void testMultiAssignFromInteger() {
shouldFail MissingMethodException, '''
Integer z = 42
def (x, y) = z
'''
}

@Test // GROOVY-11959
void testMultiAssignFromPrimitiveInt() {
shouldFail MissingMethodException, '''
int z = 42
def (x, y) = z
'''
}

@Test // GROOVY-11959
void testMultiAssignFromPrimitiveLong() {
shouldFail MissingMethodException, '''
long z = 42L
def (x, y) = z
'''
}

@Test // GROOVY-11959
void testMultiAssignFromPrimitiveDouble() {
shouldFail MissingMethodException, '''
double z = 4.2d
def (x, y) = z
'''
}

@Test
void testMultiAssignFromCalendar() {
assertScript '''
Expand Down
Loading