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

Syntactic sugar for set method calls in conflict with class member declarations

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.0-beta-1
    • Fix Version/s: 2.5.8, 3.0.0-beta-2
    • Component/s: Compiler
    • Labels:
      None

      Description

      Groovy 3.0.0 beta 1 has broken code that earlier worked in Alpha 4:
      Say you have a Java class with a setTitle(String) method. Now you override this class with a Groovy class. In it you declare the following member variable:

      JLabel title = new JLabel("skin");

      This breaks the Groovy compiler in v3.0.0 beta 1 (but not alpha 4) with the following error:
      The return type of javax.swing.JLabel getTitle() in Script34$1$12 is incompatible with java.lang.String in se.datadosen.component.ControlPanel
      . At [-1:-1]  @ line -1, column -1.

      Two things are noteworthy here:
      1) The line number references (-1) are broken
      2) Instead of letting the declared "title" variable hide the ability to call setTitle on the base class using the syntactic sugar of Groovy (foo = being syntactic sugar for setFoo(...)), it now bails out with this error, breaking Java compatibility. I expected this declaration to be allowed and simply hide the ability to call setTitle on the base class via that syntactic sugar.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                davidekholm David Ekholm
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h