ceylon icon indicating copy to clipboard operation
ceylon copied to clipboard

Backend error: name clash when satisfying both Iterable and Category

Open kingjon3377 opened this issue 7 years ago • 1 comments

The following code fails to compile with a backend error:

interface Clashing satisfies {<String->String>*}&Category<String> {}

The error is:

source/nameclash/run.ceylon:1: error: Ceylon backend error: name clash: contains(Element) in Category and contains(Object) in Iterable have the same erasure, yet neither overrides the other
interface Clashing satisfies {<String->String>*}&Category<String> {}
^
  where Element is a type-variable:
    Element extends Object declared in interface Category

ceylon --version reports ceylon version 1.3.3 0d594b3 (Contents May Differ), and it is installed on this Mac OS X Sierra system using Homebrew.

kingjon3377 avatar Jul 08 '18 22:07 kingjon3377

I've confirmed the bug. However, please note that there is a very trivial workaround. Just remove &Category<String>, since it's not doing any real work here, or replace it with &Category<Object>.

Since all Iterables already inherit Category<Object>, you can't "narrow" the sort of Category on a subclass (that would be unsound). Instead, Ceylon just takes the intersection of Category<Object>&Category<String> which is Category<Object> since Category is contravariant.

gavinking avatar Sep 14 '18 23:09 gavinking