#1039 It not typed as Obj? correctly

Akcelisto Thu 25 Mar 2010

static Void main(){
  echo(["",null].findAll{it!=null})
}

throws

sys::NullErr: Coerce to non-null

Why?

Addition

I found more simple.

static Void main(){
  null{
    echo(it)
  }
}

throws

sys::NullErr: Coerce to non-null

Why?

tactics Thu 25 Mar 2010

Apparently, the it special object isn't handling null. The coerce message is coming up because it's trying to cast null to an Obj in both cases.

Akcelisto Thu 25 Mar 2010

What is mean cast to sys::Obj? I think, everything is instance of sys::Obj.

--

1st case

[null].each|v|{
  echo(v)
}

2nd case

[null].each{
  echo(it)
}

It seems 1st and 2nd case are identical. But indeed they have different output.

1st case

null

2nd case

sys::NullErr: Coerce to non-null

tactics Thu 25 Mar 2010

Obj can hold any value in Fantom except for null.

In case 1, the variable v is inferring the type Obj?. Everything works.

In case 2, the special variable it is inferring the type Obj. It tries to coerce null an it blows up and you get an exception.

This is a bug. Case 2 should work the same as case 1.

brian Thu 25 Mar 2010

Promoted to ticket #1039 and assigned to brian

I think that is just a nullable bug somewhere in the compiler. If it is typed as Obj? then null should be a valid value. I suspect that is just some place where it is typed as Obj instead of Obj?.

brian Thu 25 Mar 2010

Renamed from Exclude null from List to It not typed as Obj? correctly

brian Thu 25 Mar 2010

Ticket resolved in 1.0.53

Took a while to track down, but its a one line fix

Login or Signup to reply.