Creating a range of Ordinal values from enumerated type objects.

22 views
Skip to first unread message

Roland Tepp

unread,
Oct 25, 2012, 4:06:59 AM10/25/12
to ceylon...@googlegroups.com
Hi, I think I have stumbled upon an issue in compiler/type resolver:

When defining an enumerated type satisfying an Ordinal interface  and trying to create a Range for these, I get an error from compiler/type resolver stating that the types are not compatible.

The minimal test case is pasted below and the error messages are pasted after that.

shared abstract class Enumeration(integer) of one | two | three

satisfies Comparable<Enumeration> & Ordinal<Enumeration> {

shared Integer integer;

shared actual Comparison compare(Enumeration other) {

return this.integer <=> other.integer;

}

shared actual Integer distanceFrom(Enumeration other) {

return this.integer.distanceFrom(other.integer);

}

}


shared object one extends Enumeration(1) {

shared actual String string = "one";

shared actual Enumeration predecessor = bottom;

shared actual Enumeration successor { return two; }

}


shared object two extends Enumeration(2) {

shared actual String string = "two";

shared actual Enumeration predecessor { return one; }

shared actual Enumeration successor { return three; }

}


shared object three extends Enumeration(3) {

shared actual String string = "three";

shared actual Enumeration predecessor { return two; }

shared actual Enumeration successor = bottom;

}


void run() {

for( Enumeration e in one .. three){

print( e );

}

}


The underlined range literal expression in above for expression yields the following two error messages by the backend:
   operand expressions must be of compatible ordinal type: three is not assignable to Ordinal<three|one> range.ceylon /testcase/source line 35 Ceylon Error
   operand expressions must be of compatible ordinal type: one is not assignable to Ordinal<three|one> range.ceylon /testcase/source line 35 Ceylon Error

Stephane Epardaud

unread,
Oct 25, 2012, 4:45:47 AM10/25/12
to ceylon...@googlegroups.com
In the backend? That looks to me to be a typechecker error. Doesn't
the IDE tell you about this even before you compile it?
--
Stéphane Épardaud

Stephane Epardaud

unread,
Oct 25, 2012, 4:47:28 AM10/25/12
to ceylon...@googlegroups.com
Can you please file it at https://github.com/ceylon/ceylon-spec/issues/new ?
--
Stéphane Épardaud

Gavin King

unread,
Oct 25, 2012, 5:13:31 AM10/25/12
to ceylon...@googlegroups.com
Hrm. So when Enrique added distanceFrom() to Ordinal he had to change
Ordinal to be invariant in its type parameter (it was covariant
before). But that broke the approach that the typechecker uses for
inferring the type of Range.

We need to think about this one.

Roland, would you submit an issue please?
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ceylon-users/-/ibXHawMt1sYJ.
> To post to this group, send email to ceylon...@googlegroups.com.
> To unsubscribe from this group, send email to
> ceylon-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ceylon-users?hl=en.



--
Gavin King
gavin...@gmail.com
http://in.relation.to/Bloggers/Gavin
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org

Roland Tepp

unread,
Oct 25, 2012, 7:37:42 AM10/25/12
to ceylon...@googlegroups.com

Gavin King

unread,
Oct 25, 2012, 7:38:42 AM10/25/12
to ceylon...@googlegroups.com
Thanks.

On Thu, Oct 25, 2012 at 1:37 PM, Roland Tepp <luo...@gmail.com> wrote:

> Here's the issue: https://github.com/ceylon/ceylon-spec/issues/444



Reply all
Reply to author
Forward
0 new messages