#1255 Passing uninitialized field as non-null

vkuzkokov Fri 15 Oct 2010

Here's the source to do it:

class Main {
  Str z
  new make() {
    doSth(z)
    z = "13"
  }
  Void doSth (Str s){
    u := [s]
    echo(u.typeof)
    echo(u)
  }
  static Void main()
  {
    Obj x := Main()
  }
}

It addresses at least two different wacky situations (I'm not sure whether any of them is in fact a bug).

First one: we created a Str[] and then put null in it. If I'm not mistaken it was discussed somewhere else.

Second one: we use uninitialized non-value field as if it can't be null.

What I expected to see is sys::NullErr: Coerce to non-null on calling doSth.

brian Tue 19 Oct 2010

That is pretty much the same problem as the const field - if you let uninitialized references escape, then bad stuff can happen.

Login or Signup to reply.