[jira] [Commented] (GROOVY-9363) False "Constructor call must be the first statement in a constructor"

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-9363) False "Constructor call must be the first statement in a constructor"

Eric Milles (Jira)

    [ https://issues.apache.org/jira/browse/GROOVY-9363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17014757#comment-17014757 ]

Björn Kautler commented on GROOVY-9363:
---------------------------------------

Assuming you mean "does not", that doesn't make it much better.

If there is no super-constructor call like with
{code:java}
Bar() {
    println 'foo'
}
{code}
the message is "java.lang.NoSuchMethodError: Foo: method 'void <init>()' not found".

 

If the constructor call is with parens, but not as first statement like with
{code:java}
Bar() {
    println 'foo'
    super({ null })
} {code}
the message again is "Constructor call must be the first statement in a constructor."

which makes sense in this case.

Even with
{code:java}
Bar() {
    println 'foo'
    super { null }
}{code}
you get the same message.

So it seems {{super \{ null }}} actually *is* recognized as constructor call, but somehow the compiler thinks there is some statement before it, even if there isn't.

> False "Constructor call must be the first statement in a constructor"
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-9363
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9363
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.8
>            Reporter: Björn Kautler
>            Priority: Major
>
> Given this script:
> {code:groovy}
> import java.util.function.Supplier
> class Foo {
>     Foo(Supplier<?> supplier) {
>     }
> }
> class Bar extends Foo {
>     Bar() {
>         super { null }
>     }
> }
> new Bar()
> {code}
> I'd expect everything to be ok, but the compiler complains that "Constructor call must be the first statement in a constructor".
> Using {{super(\{ null \})}} instead works fine.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)