Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.5.6, 1.6-beta-1
-
None
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.