After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 639990 - var foo = null should not be allowed
var foo = null should not be allowed
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
unspecified
Other Linux
: Urgent minor
: ---
Assigned To: Vala maintainers
Vala maintainers
test-case trivial-patch accepts-invalid
Depends on:
Blocks:
 
 
Reported: 2011-01-19 20:52 UTC by Luca Bruno
Modified: 2017-02-18 16:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Do not allow initializing var-type local variable with null type. (959 bytes, patch)
2011-01-19 20:59 UTC, Luca Bruno
none Details | Review
Simplify determining the type of conditional expressions (4.74 KB, patch)
2011-05-27 14:15 UTC, Luca Bruno
none Details | Review
Forbid var declaration with null initializer (940 bytes, patch)
2011-05-27 14:16 UTC, Luca Bruno
none Details | Review

Description Luca Bruno 2011-01-19 20:52:34 UTC
Hello,
actually var foo = null; makes foo be of NullType, this should not be allowed as well as var foo; is not allowed.
Comment 1 Luca Bruno 2011-01-19 20:59:39 UTC
Created attachment 178779 [details] [review]
Do not allow initializing var-type local variable with null type.

Fixes bug 639990.
Comment 2 Jürg Billeter 2011-05-20 18:25:51 UTC
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;
							                                                   ^^^^
Comment 3 Luca Bruno 2011-05-27 14:15:29 UTC
Created attachment 188756 [details] [review]
Simplify determining the type of conditional expressions
Comment 4 Luca Bruno 2011-05-27 14:16:12 UTC
Created attachment 188757 [details] [review]
Forbid var declaration with null initializer

Fixes bug 639990.
Comment 5 pancake 2013-02-17 23:50:53 UTC
Vala generates gpointer, and I think 'var foo = null' should be valid and associated to PointerType instead of NullType.
Comment 6 Daniel Espinosa 2017-02-18 16:49:05 UTC
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.