[Vala] Why do regular reference types leak null?



The following code compiles with no warnings with the 0.7.3 compiler
and segfaults at runtime. I understand that nullable types can be null
but why are regular reference types allowed to be null? I noticed that
if the return type of make_foo is changed from Foo? to Foo I at least
get a warning. But both assignments in main() go unnoticed.

class Foo { public int i; }
Foo? make_foo () { return null; }
void main ()
{
        Foo f1 = make_foo ();
        Foo f2 = null;
        message (f1.i.to_string () + f2.i.to_string ());
}

I'm also curious how vala will handle a Foo? -> Foo cast. Will the
type system be statically null-check aware, silently changing Foo? to
Foo inside 'if (foo != null) {...}'?

-Sam Danielson



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]