groovy
  1. groovy
  2. GROOVY-4966

VeryifyError in multi-dimensional array usage: Incompatible argument to function

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.5, 2.0-beta-2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OSX 10.7, jdk 1.6.0_26-b03-383-11A511
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      When running this code, I get the attached error. Please see: http://pastie.org/2327875. Dropping back to 1.7 seems to work. I'm running 1.8.1, but the problem also exists in 1.8.0.

        Activity

        Hide
        Chris added a comment -

        Sorry, this error is not present in 1.8.0, I forgot to recompile after changing the gdk. It does remain in 1.8.1, however.

        Show
        Chris added a comment - Sorry, this error is not present in 1.8.0, I forgot to recompile after changing the gdk. It does remain in 1.8.1, however.
        Hide
        Roshan Dawrani added a comment -

        Here is a shorter piece of code that reproduces it:

        char[] c1 = 'xy'.toCharArray()
        getIndex(c1[0])
        
        /*
        //Note: This works fine
        char a = 'a'
        getIndex(a)
        */
        
        def getIndex(char base) {}
        
        Show
        Roshan Dawrani added a comment - Here is a shorter piece of code that reproduces it: char [] c1 = 'xy'.toCharArray() getIndex(c1[0]) /* //Note: This works fine char a = 'a' getIndex(a) */ def getIndex( char base) {}
        Hide
        Roshan Dawrani added a comment -

        Corrected the bug title a bit.

        Show
        Roshan Dawrani added a comment - Corrected the bug title a bit.
        Hide
        Roshan Dawrani added a comment -

        Here is the shorter version of the code that currently reproduces the bug. (Probably the shorter version supplied earlier resulted in a VerifyError due to some other reason, and that piece of code works now.)

        class ParalinearTest {
            static void main(args){}
        
            void zeroMatrix(int[][] matrix) {
                matrix[0][0]
            }
        }
        

        The bug can be seen in action on Groovy Web Console here: http://groovyconsole.appspot.com/edit/597001

        Show
        Roshan Dawrani added a comment - Here is the shorter version of the code that currently reproduces the bug. (Probably the shorter version supplied earlier resulted in a VerifyError due to some other reason, and that piece of code works now.) class ParalinearTest { static void main(args){} void zeroMatrix( int [][] matrix) { matrix[0][0] } } The bug can be seen in action on Groovy Web Console here: http://groovyconsole.appspot.com/edit/597001
        Hide
        Roshan Dawrani added a comment -

        The VerifyError is caused by how multi-dimensional arrays are handled on the fast-path.

        For "int[][] matrix", matrix[0][0] is written in the class like:

        BytecodeInterface8.intArrayGet(BytecodeInterface8.objectArrayGet(matrix, 0), 0)
        

        when it should have been written as:

        BytecodeInterface8.intArrayGet((int[])ScriptBytecodeAdapter.castToType(BytecodeInterface8.objectArrayGet(matrix, 0), int[]), 0)
        

        The result of BytecodeInterface8.objectArrayGet was not casted to int[], which made the BytecodeInterface8.intArrayGet() call invalid.

        The following patch solves the issue (tested locally with the latest shorter version and the original testcase of the bug):

        @@ -166,11 +166,15 @@ public class BinaryExpressionMultiTypeDispatcher extends BinaryExpressionHelper
                         leftExp.visit(acg);
                         os.doGroovyCast(leftTypeOrig);
                         rightExp.visit(acg);
                         os.doGroovyCast(int_TYPE);
                         bew.arrayGet(operation, false);
        -                os.replace(leftType,2);
        +                if(bew instanceof BinaryObjectExpressionHelper) {
        +                    os.replace(ClassHelper.OBJECT_TYPE,2);
        +                } else {
        +                    os.replace(leftType,2);
        +                }
                     } else {
                         super.evaluateBinaryExpression(message, binExp);
                     }
                 } else {
                     int operationType = getOperandConversionType(leftType,rightType);
        
        Show
        Roshan Dawrani added a comment - The VerifyError is caused by how multi-dimensional arrays are handled on the fast-path. For "int[][] matrix", matrix [0] [0] is written in the class like: BytecodeInterface8.intArrayGet(BytecodeInterface8.objectArrayGet(matrix, 0), 0) when it should have been written as: BytecodeInterface8.intArrayGet(( int [])ScriptBytecodeAdapter.castToType(BytecodeInterface8.objectArrayGet(matrix, 0), int []), 0) The result of BytecodeInterface8.objectArrayGet was not casted to int[], which made the BytecodeInterface8.intArrayGet() call invalid. The following patch solves the issue (tested locally with the latest shorter version and the original testcase of the bug): @@ -166,11 +166,15 @@ public class BinaryExpressionMultiTypeDispatcher extends BinaryExpressionHelper leftExp.visit(acg); os.doGroovyCast(leftTypeOrig); rightExp.visit(acg); os.doGroovyCast(int_TYPE); bew.arrayGet(operation, false ); - os.replace(leftType,2); + if (bew instanceof BinaryObjectExpressionHelper) { + os.replace(ClassHelper.OBJECT_TYPE,2); + } else { + os.replace(leftType,2); + } } else { super .evaluateBinaryExpression(message, binExp); } } else { int operationType = getOperandConversionType(leftType,rightType);
        Hide
        blackdrag blackdrag added a comment -

        Well spotted Roshan! If that patch works with a 3d and 4d array too, then it would be nice of you to commit it. But I think it will work

        Show
        blackdrag blackdrag added a comment - Well spotted Roshan! If that patch works with a 3d and 4d array too, then it would be nice of you to commit it. But I think it will work
        Hide
        Roshan Dawrani added a comment -

        Extended the test to cover 3d, 4d arrays also. They also work now.

        Show
        Roshan Dawrani added a comment - Extended the test to cover 3d, 4d arrays also. They also work now.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Chris
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: