Paco Soberón
2016-03-31 22:01:11 UTC
I just found that, while this code raises a compiler error, as expected:
value tuple = Tuple<Integer, Boolean>(true, []); // Boolean is not
assignable to upper bound Integer
This other code compiles without problems:
void foo(Tuple<Integer, Boolean> tuple) {}
Tuple<Integer, Boolean> bar() => nothing;
Narrowing my observation to a simpler generic class, this code doesn't
compile:
class Generic<Parent, Child>()
given Child satisfies Parent {}
value generic = Generic<Integer, Boolean>();
But this code does:
void foo(Generic<Integer, Boolean> generic) {}
Generic<Integer, Boolean> bar() => nothing;
Of course, I'm aware that even if it compiles, the code is completely
useless, since you're not going to be able to create a valid object to pass
to foo() or return from bar().
But I am still curious... why the compiler doesn't complain? Doesn't it
check the generic constraints when declaring a type? Does it only do it
when instantiating an object?
Regards.
value tuple = Tuple<Integer, Boolean>(true, []); // Boolean is not
assignable to upper bound Integer
This other code compiles without problems:
void foo(Tuple<Integer, Boolean> tuple) {}
Tuple<Integer, Boolean> bar() => nothing;
Narrowing my observation to a simpler generic class, this code doesn't
compile:
class Generic<Parent, Child>()
given Child satisfies Parent {}
value generic = Generic<Integer, Boolean>();
But this code does:
void foo(Generic<Integer, Boolean> generic) {}
Generic<Integer, Boolean> bar() => nothing;
Of course, I'm aware that even if it compiles, the code is completely
useless, since you're not going to be able to create a valid object to pass
to foo() or return from bar().
But I am still curious... why the compiler doesn't complain? Doesn't it
check the generic constraints when declaring a type? Does it only do it
when instantiating an object?
Regards.
--
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 ceylon-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/CAMfU2ZQrF8FC9oYPkCNo1963Bub1wFP%3DGiqiK9ah%3Dy_Jn9joKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
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 ceylon-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/CAMfU2ZQrF8FC9oYPkCNo1963Bub1wFP%3DGiqiK9ah%3Dy_Jn9joKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.