[
https://issues.apache.org/jira/browse/GROOVY-11803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18039466#comment-18039466
]
ASF GitHub Bot commented on GROOVY-11803:
-----------------------------------------
eric-milles opened a new pull request, #2338:
URL: https://github.com/apache/groovy/pull/2338
Probably indexes more methods than necessary, but not easy to check if an
interface is "groovy" and has method(s) with body.
> 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
> Assignee: Eric Milles
> Priority: Major
>
> 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)