[Vala] Why do regular reference types leak null?
- From: Sam Danielson <samdanielson gmail com>
- To: Vala ML <vala-list gnome org>
- Subject: [Vala] Why do regular reference types leak null?
- Date: Thu, 13 Aug 2009 17:48:21 -0700
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]