GNOME Bugzilla – Bug 639990
var foo = null should not be allowed
Last modified: 2017-02-18 16:49:05 UTC
Hello, actually var foo = null; makes foo be of NullType, this should not be allowed as well as var foo; is not allowed.
Created attachment 178779 [details] [review] Do not allow initializing var-type local variable with null type. Fixes bug 639990.
This would currently break bootstrapping: valaassignment.vala:489.89-489.92: error: var declaration not allowed with non-typed initializer codegen.store_field (field, instance && ma.inner != null ? ma.inner.target_value : null, new_value); ^^^^ valaassignment.vala:500.103-500.106: error: var declaration not allowed with non-typed initializer target_value = codegen.load_field (field, instance && ma.inner != null ? ma.inner.target_value : null); ^^^^ valagirparser.vala:707.59-707.62: error: var declaration not allowed with non-typed initializer var m = getter != null ? getter.symbol as Method : null; ^^^^ valagirparser.vala:727.59-727.62: error: var declaration not allowed with non-typed initializer var m = setter != null ? setter.symbol as Method : null; ^^^^
Created attachment 188756 [details] [review] Simplify determining the type of conditional expressions
Created attachment 188757 [details] [review] Forbid var declaration with null initializer Fixes bug 639990.
Vala generates gpointer, and I think 'var foo = null' should be valid and associated to PointerType instead of NullType.
As for Vala 0.34 var l = null; use gpointer as type for *l*, then using (l == null) is a valid sentence. I could ask for usefulness of such declaration in Vala, may useful in C but in vala *var* should be used only on typed declaration.