ceylon/ceylon-js — Issue #46: case (is...) is broken
Author: ikasiuk
Created: 2012-02-17 20:01:48+00:00
State: open
Labels: bug

This currently doesn't work:

```
class C(Integer? x) {
switch (x)
case (is Integer) {print(x.string);}
else {}
}
```

Here is the relevant part of the resulting JS code (capture style):

```
function C(x, $$c){
if ($$c===undefined)$$c=new C.$$;
//Switch
var tmpvar$1=x;
if ($$$cl15.isOfType(tmpvar$1,'ceylon.language.Integer')===$$$cl15.getTrue()) {
$$$cl15.print(getX().getString());
}
else {}

return $$c;
}
```

That fails because `getX` does not exist. The problem is that `case (is...)` introduces a new local variable `x` which shadows the outer `x`. The code inside the case block expects a getter for that variable, but we currently don't define any. Actually we have already solved this same problem for `if (is...)`/`while (is...)` so maybe we can reuse some of that logic.