Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11375

Power binary expression finds incorrect type - currently uses declaration inferred type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.0.0-alpha-8, 4.0.21
    • 5.0.0-alpha-9
    • None

    Description

      For this code:

      @groovy.transform.CompileStatic
      def method() {
          var temp = 'foo'
          temp = temp.size()
          assert temp ** temp == 27
      }
      
      method()
      

      The compiler gives this error:

      BUG! exception in phase 'class generation' in source unit 'ConsoleScript3' At line 10 column 8
      On receiver: temp with message: power and arguments: temp
      This method should not have been called. Please try to create a simple example reproducing
      this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY
      
      	at org.codehaus.groovy.classgen.asm.sc.StaticTypesCallSiteWriter.makeSingleArgumentCall(StaticTypesCallSiteWriter.java:582)
      
      	at org.codehaus.groovy.classgen.asm.InvocationWriter.makeSingleArgumentCall(InvocationWriter.java:626)
      
      	at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateBinaryExpression(BinaryExpressionHelper.java:602)
      
      	at org.codehaus.groovy.classgen.asm.BinaryExpressionMultiTypeDispatcher.evaluateBinaryExpression(BinaryExpressionMultiTypeDispatcher.java:242)
      
      	at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.eval(BinaryExpressionHelper.java:264)
      
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitBinaryExpression(AsmClassGenerator.java:849)
      ...
      

      We apply flow typing for the receiver but not the argument type. This looks like a case that should be handled where we currently have "TODO: more cases ..." in StaticTypesCallSiteWriter.

      The same situation occurs for the shift operators and plus etc., e.g.:

      assert temp << temp == 24
      assert temp + temp == 6
      

      Attachments

        Activity

          People

            emilles Eric Milles
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: