ceylon/ceylon-spec — Issue #204: exists does not meet spec
Author: RossTate
Created: 2012-02-20 17:43:42+00:00
State: open

This is the definition of `exists` according to the spec:

> `if (exists x)` is equivalent to `if (is X x)` where `x` is an expression of type `X?`

According to that the following program

```
function foo(T t) {
T? mt = t;
return exists mt;
}
```

should always return `true`. However, it doesn't. In particular, `foo(null)` returns `false` (at least using the Ceylon web runner).

Also, the spec says that `exists` is defined on any expression whose type is

> of form `X?` for some type `X`

According to that and the fact that `T` is a subtype of `T?`, the following program is well typed:

```
function foo(T t) {
return exists t;
}
```

However, this program is rejected (at least using the Ceylon web runner).

I believe the problem is that `T?` stands for `T|Nothing`, and others disagree, but regardless either the spec or the implementation is wrong.