Discussion:
[groovy-dev] Ambiguous DefaultMethods.equals resolution
Thibault Kruse
2014-12-10 09:46:58 UTC
Permalink
Hi,

in another thread I mentioned this symptom in Groovy, so this is a bump:

class UnorderedList<E> extends ArrayList<E> implements Set<E> {
UnorderedList( Collection items ) {
this.addAll(items)
}
public static void main(String[] args) {
UnorderedList x = new UnorderedList([1,2,3])
UnorderedList y = new UnorderedList([3,1,2])

assert x.equals( y ) // true via DefaultGroovyMethods equals(Set, Set)
assert x == y // false via DefaultGroovyMethods equals(List, List)
}
}

Is this a Bug or feature?

I also note that this code fails Static type checking because
allegedly x.equals(y) is an ambiguous Method call to Groovy, I also
guess because of DefaultGroovyMethods. Not sure what proper dynamic
behavior should be here, but equals() taking a different route than ==
seems not the ideal solution.

I am aware that it does not make much sense to implement both Set and
List, since their semantics are different. Yet the way Groovy behaves
when dynamically typed seems odd, hinting at a possible bug somewhere.

cheers,
Thibault

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Jochen Theodorou
2014-12-10 09:59:47 UTC
Permalink
Post by Thibault Kruse
Hi,
class UnorderedList<E> extends ArrayList<E> implements Set<E> {
UnorderedList( Collection items ) {
this.addAll(items)
}
public static void main(String[] args) {
UnorderedList x = new UnorderedList([1,2,3])
UnorderedList y = new UnorderedList([3,1,2])
assert x.equals( y ) // true via DefaultGroovyMethods equals(Set, Set)
assert x == y // false via DefaultGroovyMethods equals(List, List)
}
}
Is this a Bug or feature?
a bug I guess... DefaultTypeTransformation#compareEqual does ignore that
something could implement List and Set at the same time
Post by Thibault Kruse
I also note that this code fails Static type checking because
allegedly x.equals(y) is an ambiguous Method call to Groovy, I also
guess because of DefaultGroovyMethods.
yes
Post by Thibault Kruse
I am aware that it does not make much sense to implement both Set and
List, since their semantics are different. Yet the way Groovy behaves
when dynamically typed seems odd, hinting at a possible bug somewhere.
It does indeed not really make sense, but I guess this case should be
still considered

bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Thibault Kruse
2014-12-10 10:15:53 UTC
Permalink
Created as https://jira.codehaus.org/browse/GROOVY-7205
Post by Jochen Theodorou
Post by Thibault Kruse
Hi,
class UnorderedList<E> extends ArrayList<E> implements Set<E> {
UnorderedList( Collection items ) {
this.addAll(items)
}
public static void main(String[] args) {
UnorderedList x = new UnorderedList([1,2,3])
UnorderedList y = new UnorderedList([3,1,2])
assert x.equals( y ) // true via DefaultGroovyMethods equals(Set, Set)
assert x == y // false via DefaultGroovyMethods equals(List, List)
}
}
Is this a Bug or feature?
a bug I guess... DefaultTypeTransformation#compareEqual does ignore that
something could implement List and Set at the same time
Post by Thibault Kruse
I also note that this code fails Static type checking because
allegedly x.equals(y) is an ambiguous Method call to Groovy, I also
guess because of DefaultGroovyMethods.
yes
Post by Thibault Kruse
I am aware that it does not make much sense to implement both Set and
List, since their semantics are different. Yet the way Groovy behaves
when dynamically typed seems odd, hinting at a possible bug somewhere.
It does indeed not really make sense, but I guess this case should be still
considered
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...