Scott Murphy Heiberg created GROOVY-12625:
---------------------------------------------

             Summary: SC fails with ArrayIndexOutOfBoundsException for ++ or -- 
on a subscript whose element type is not a primitive or wrapper number type
                 Key: GROOVY-12625
                 URL: https://issues.apache.org/jira/browse/GROOVY-12625
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 5.0.8, 4.0.33, 6.0.0
            Reporter: Scott Murphy Heiberg


{code:groovy}
@groovy.transform.CompileStatic
def f() {
    List<BigDecimal> l = [1.0]
    l[0]++
    l
}
assert f() == [2.0]
{code}
Actual: compilation fails with "General error during instruction selection: 
Index 1 out of bounds for length 1" (ArrayIndexOutOfBoundsException in 
StaticInvocationWriter.loadArguments). The same happens for prefix and postfix 
++ and -- on a BigDecimal array, a map of BigDecimal values, a list of 
BigInteger, String, Character, char[], and a class with getAt/putAt returning 
BigDecimal.

Expected: the code compiles and the assertion passes, as it does without the 
annotation and with @TypeChecked.

The type checker resolves next() or previous() by passing the subscript 
expression to findMethodOrFail. StaticCompilationVisitor then stores next() as 
that expression's binary target, replacing getAt, so l[0] is compiled as a call 
to next with argument 0.

Seen in 4.0.33, 5.0.8 and 6.0.0.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to