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

Using 'var' in operation followed by comment fails compilation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.0-alpha-3
    • None
    • lexer, parser-antlr4
    • None
    • Windows, Java 1.8.0_152

    Description

      There seems to be some issue with scripting containing variables called "var" and then followed by a comment.

      This crashes with MultipleCompilationErrorsException (unexpected input 'return'):

      def a = var / 10
      // return bla
      return a

      This crashes with MissingPropertyException (not found: foo):

      def a = foo / 10
      // return bla
      return a
      

      This crashes with MissingPropertyException (not found: var):

      def a = var / 10
      return a
      

      This crashes with MissingPropertyException (not found: What):

      def a = var / 10
      // What is happening
      return a
      

      Works:

      def var = 10
      def a = var / 10
      return a
      

      This crashes with MultipleCompilationErrorsException (Unexpected input: '?')

      def var = 10
      def a = var / 10
      // What?
      return a
      

      Works:

      def foo = 10
      def a = foo / 10
      // What?
      return a

      I did not know that "var" was handled by Groovy. But anyway, seems something is quite off with it. We noticed this after upgrading from Groovy 2.x to 3, where the script used to work in 2.x.

      I can see in the lexer that the tokens that are recognized become really weird, with everything between "var / [..] /" becomes one token, then "/ return" fails since you of course cannot divide by 'return'.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Eliason Pontus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: