ceylon/ceylon-js — Issue #40: if (is...) can't handle unions of intersections
Author: chochos
Created: 2012-02-03 02:03:02+00:00
State: open

This works in Ceylon on the JVM:

````

interface I1 {}
interface I2 {}
interface I3 {}
interface I4 {}

class C1() satisfies I1&I2{}
class C3() satisfies I3{}

shared void test() {
C1|C3 c1 = C1();
if (is I1&I2|I3&I4 c1) {
print("yay! 1");
}
}
````

But not in JS. I modified the "is" function in ceylon.language.js (there are two, actually: one for simple types and another one for union/intersection types). The structure that is generated looks right: `{ t:'u', l:[{ t:'i', l:['tipos.I1','tipos.I2']},{ t:'i', l:['tipos.I3','tipos.I4']}]}` (a union of two intersections), but the algorithm could be flawed, or the C1 type does not have the correct info.