GNOME Bugzilla – Bug 761267
Vala lacks a null-safe member access operator
Last modified: 2018-05-22 15:30:44 UTC
Created attachment 319973 [details] [review] Patch that provides this capabilities Vala has no null-safe member access operator, written ?. in C# and Ceylon. The behavior of this operator is defined there : http://ceylon-lang.org/documentation/1.2/reference/operator/nullsafe-member/
This code gives me errors and compiler segfault class Hey : Object { public int x = 3; } void do_it (Hey h) { int? y = h?.x; if (y != null) print ("%d\n", y); } void main () { do_it (null); do_it (new Hey ()); }
-void do_it (Hey h) { +void do_it (Hey? h) { Indeed, don't know how I managed to compile my test class without error (and I didn't kept its code). The issue comes from error = check_nullsafe_member_access (context); as the expression is replaced : parent_node.replace_expression (this, temp_access); So, replacing error = by return fixes it. This fixed, your test case now shows another error: Assignment: Cannot convert from `null' to `int'. However, if you replace int with string, it works, so primitive types marked nullable are not supported.
Created attachment 320289 [details] [review] Fix a segfault and ensures the type is nullable
Created attachment 320293 [details] [review] improved patch I added a new patch: - cleaned up whitespace - used git format-patch - support primitive types - keep reference to replaced expression
If you return true from check(), doesn't that signify that there was an error?
If my previous code was right, then yes, I have omitted to invert the boolean value.
The `error =` vs `return` doesn't fix the issue, my patch does with `context.analyzer.replaced_nodes.add (this);`
Created attachment 321602 [details] [review] Improved patch Changed commit author
*** Bug 777345 has been marked as a duplicate of this bug. ***
Created attachment 343600 [details] [review] add support for null-conditional operators This patch has been improved since it was uploaded in bug 777345. (Some bugs were found in specific scenarios)
Created attachment 343601 [details] Test for null-conditional operators
Created attachment 343609 [details] [review] Add support for null-conditional operators Not allow null-conditional expression to be used as lvalue and remove unnecessary execute-permission from file I'm sorry if I annoyed you by uploading patches too frequently.
*** Bug 725356 has been marked as a duplicate of this bug. ***
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/522.