[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[Vala] Type casting
- From: Hans Vercammen <hveso3 gmail com>
- To: vala-list gnome org
- Subject: [Vala] Type casting
- Date: Mon, 21 Jan 2008 14:36:29 +0100
Hi all,
First of all, many thanks for a great initiative which has in my opinion
a very bright future!
I am not quit sure on which level invalid type casts should be
monitored, whether it be the vala compiler or the underlaying gobject.
Please view the attached test-case for details.
As I understand, it should be possible to check incompatible types at
compile time and so eliminating further errors.
Regards,
Hans
using GLib;
public class Foo : Object {
public int data { get; construct; }
public Foo (construct int data) {
}
}
public class FalseFoo : Object {
}
public class FooBar : Foo {
public FooBar (int data) {
this.data = data;
}
}
public class App : Object {
static int main (string[] args) {
/* OK implitic cast is good */
Foo foo = new FooBar (1);
/* ERROR Should require explicit cast ? */
FooBar foobar = new Foo (1);
/* OK explicit cast required */
foobar = (FooBar) foo;
/* ERROR Should require explicit cast and fail on compatibility */
Foo foo1 = new FalseFoo ();
/* ERROR should fail on compatible type */
FalseFoo falsefoo = (FalseFoo) foo;
/* Silently accept null cast ? */
foobar = null;
foo = (Foo) foobar;
/* Nullexception */
foo.data = 5;
/* OK foreach implicit upcast */
foreach (Foo item in new FooBar[3]) {
}
/* ERROR should require explicit cast, not allowed in foreach */
foreach (FooBar item in new Foo[3]) {
}
return 0;
}
}
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]