eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

Backend error: name clash when satisfying both Iterable and Category #7385

Open kingjon3377 opened 5 years ago

kingjon3377 commented 5 years ago

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.

gavinking commented 5 years ago

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.