ceylon/ceylon-compiler — Issue #219: Sequence: Access via [n]
Author: alexanderbell
Created: 2011-11-23 12:30:38+00:00
State: open

Hi,

I tried to use Sequences with a user defined type:

Emplyee class:

```ceylon
shared class Employee(String pFirstname, String pLastname)
extends Person() satisfies LegalEntity {
shared String firstname = pFirstname;
shared String lastname = pLastname;
shared String fullname = "Employee " lastname ", " firstname "";
shared actual String info {
return "Employee Info " firstname "";
}
}
```

Now, I wann store some employees in a sequence:

```ceylon
Employee[] employees = { Employee("Alex", "Bell"), Employee("Just", "Me") };
```

Afterward I pass the sequence to a method. In that method I wanna read the first element for instance:

```ceylon
Employee? employee = employees[0];
```
Ok, to access the employee I have to do a null check:

Option 1:

```ceylon
if(exists employee) {
print(employee.firstname);
}
```

Option 2:

```ceylon
if(is Employee employee) {
print(employee.firstname);
}
```

Unfortuantely it doesn't work. IMO it's a problem of the access method of the sequence.
When I replace `Employee? employee = employees[0];` with `Employee? employee = employees.item(0);` it works fine.

cheers Alex