[ 
https://issues.apache.org/jira/browse/GROOVY-11804?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles reassigned GROOVY-11804:
------------------------------------

    Assignee: Eric Milles

> Groovy 5 doesn't handle implicit properties
> -------------------------------------------
>
>                 Key: GROOVY-11804
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11804
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 5.0.2
>            Reporter: Ed T
>            Assignee: Eric Milles
>            Priority: Major
>
> The following code compiles and works find in Groovy 4 (tested with version
> 4.0.24 and 4.0.29). It no longer compiles with Groovy 5 (tested with version
> 5.0.2). All ran on JDK25.
>  
> {code:java}
> interface CustomComparable<Owner extends Comparable, O> {
>    Owner getOwner()
>    default boolean isLessThan(O other) {
>       owner < other
>    }
>    default boolean isLessThanOrEqualTo(O other) {
>       owner <= other
>    }
>    default boolean isEqualTo(O other) {
>       owner == other
>    }
>    default boolean isGreaterThan(O other) {
>       owner > other
>    }
>    default boolean isGreaterThanOrEqualTo(O other) {
>       owner >= other
>    }
>    default isBetween(O left, O right) {
>       owner >= left && owner <= right
>    }
> }
> class MyString implements Comparable<Object>, CustomComparable<MyString, 
> String> {
>    private String str
>    
>    MyString(String str) {
>       this.str = str
>    }
>    
>    MyString getOwner() {
>       return this
>    }
>    @Override
>    int compareTo(Object o) {
>       String ostr
>       if (o instanceof MyString) {
>          ostr = ((MyString) o).str
>       } else if (o instanceof String) {
>          ostr = (String) o
>       } else {
>          throw new UnsupportedOperationException("can't compare with object 
> of class: ${o.class}")
>       }
>       return str.compareTo(ostr)
>    }
> }
> s = new MyString("abc")
> println s.isEqualTo("abc")
> {code}
>  
> When run, Groovy 5 compiler complains the following.
> {code:java}
> groovy.lang.MissingPropertyException: No such property: owner for class: 
> MyString     at CustomComparable.isEqualTo(ConsoleScript0:14)        at 
> ConsoleScript0.run(ConsoleScript0:60) {code}
> Groovy 4.x works just fine.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to