Paul King created GROOVY-11803:
----------------------------------
Summary: Property shorthand not working for default methods in
interfaces without @CompileStatic
Key: GROOVY-11803
URL: https://issues.apache.org/jira/browse/GROOVY-11803
Project: Groovy
Issue Type: Bug
Reporter: Paul King
The following script fails:
{code:groovy}
interface Foo {
default int barSize() { bar.size() }
String getBar()
}
class Baz implements Foo {
String getBar() { 'BAR' }
}
assert new Baz().barSize() == 3
{code}
With this error:
{noformat}
groovy.lang.MissingPropertyException: No such property: bar for class: Baz
{noformat}
Workaround 1: Use getter:
{code:groovy}
interface Foo {
default int barSize() { getBar().size() }
String getBar()
}
class Baz implements Foo {
String getBar() { 'BAR' }
}
assert new Baz().barSize() == 3
{code}
Workaround 2: use @CompileStatic:
{code:groovy}
@groovy.transform.CompileStatic
interface Foo {
default int barSize() { bar.size() }
String getBar()
}
class Baz implements Foo {
String getBar() { 'BAR' }
}
assert new Baz().barSize() == 3
{code}
I think this is a bug but if we can't get this to work for dynamic Groovy, I
think we need to improve the documentation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)