groovy
  1. groovy
  2. GROOVY-2836

Misleading MissingMethodException thrown when this() is called inside a constructor

    Details

    • Number of attachments :
      1

      Description

      class Foo {
          Foo(String s) {}
      
          Foo(Date d) {
              println "call to this() must be the first statement of a ctor"
              this(d.toString())
          }
      }
      
      new Foo(new Date())
      

      In the snippet above, I'm calling this() after a println call.
      But in Java, it is mandatory that calls to this() or super() inside a constructor are the first statements of the block.
      Here I get the following stacktrace:

      groovy.lang.MissingMethodException: No signature of method: Foo.call() is applicable for argument types: (java.lang.String) values: {Fri May 16 23:48:20 CEST 2008}
      	at Foo.invokeMethod(Script35)
      	at Foo.<init>(Script35:6)
      	at Script35.run(Script35:10)
      

      The compiler should check that calls to this() or super() are done as the first statement, and not afterwards.

        Activity

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Guillaume Laforge
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: