TypeChecker with Interface

35 views
Skip to first unread message

vBeauPers

unread,
Aug 19, 2015, 8:48:31 AM8/19/15
to ceylon-dev
Hi, working on Eclipse IDE with Ceylon 1.1.1 (2015/07/23)
Just for working with type subtype/supertype, I create a custom Consumer<in E> and two interfaces Inter1 and Inter2.
then I try typing that code :
value c = Consumer<Inter1|Inter2>();
if (is Consumer<Inter1>() c) { // there should be a compile error
 
// well, it is a super type, it should not narrow
 
print("ok");
}
print("end");


firstly it compiles (if I replace Inter1 with String and Inter2 with Integer, it dont), but `Consumer<Inter1>` is a supertype of `Consumer<Inter1|Inter2>`, secondly at execution it does not print ok.

I was unable to find if this bug as been reported.


I also remark that type checker consider Producer<Inter1> & Producer<Inter2> equivalent to Producer<Inter1&Inter2> which is right (Ceylon does not permits satisfying multi times Producer) but does not correspond to the spec. And curiously it does not apply this equivalence in Invariant.


Stephane Epardaud

unread,
Aug 19, 2015, 8:51:01 AM8/19/15
to ceylon-dev
You have a funny typo in your code:

value c = Consumer<Inter1|Inter2>();  // here you instantiated a Consumer<Inter1|Inter2>
if (is Consumer<Inter1>() c) { // here you're testing for type Callable<Consumer<Inter1>,[]>

  print("ok");
}
print("end");

So a '()' snuck in your 'is' test, turning it into a Callable type.

--
You received this message because you are subscribed to the Google Groups "ceylon-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
To post to this group, send email to ceylo...@googlegroups.com.
Visit this group at http://groups.google.com/group/ceylon-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/1edddf9f-6353-4605-a997-6346e56bf20a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stéphane Épardaud

vBeauPers

unread,
Aug 19, 2015, 1:14:37 PM8/19/15
to ceylon-dev
hoooo, sorry about that, forget it.

vBeauPers

unread,
Aug 19, 2015, 1:34:04 PM8/19/15
to ceylon-dev
thx


On Wednesday, August 19, 2015 at 2:51:01 PM UTC+2, Stéphane Épardaud wrote:
Reply all
Reply to author
Forward
0 new messages