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

Eric Milles commented on GROOVY-11803:
--------------------------------------

When populating the property map for Baz, {{MetaClassImpl.setUpProperties}} 
does not index "stray" properties for super interfaces.  This could be limited 
to interfaces with at least one default method.  One difficulty is that 
{{metaMethodIndex}} is not filled for super interfaces, only for super classes.

> 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)

Reply via email to