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 611223 - Null coalescing operator (??) incorrect return type
Null coalescing operator (??) incorrect return type
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Non-null
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 729488 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-02-26 19:46 UTC by Sam
Modified: 2017-04-17 10:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A sample program that illustrates the bug (363 bytes, text/x-vala)
2010-02-26 19:46 UTC, Sam
  Details
Make right type dominate in ?? operator (913 bytes, patch)
2010-03-11 23:45 UTC, Marc-Andre Lureau
needs-work Details | Review
Fix + test-case (5.47 KB, patch)
2017-04-11 19:29 UTC, Marvin W
committed Details | Review

Description Sam 2010-02-26 19:46:04 UTC
Created attachment 154788 [details]
A sample program that illustrates the bug

The null coalescing operator (??) should return a non-nullable type.

The operator should take a nullable type on the left hand side, a non-nullable type on the right hand side, and return a non-nullable type.
Comment 1 zarevucky.jiri 2010-02-27 13:43:09 UTC
> The operator should take a nullable type on the left hand side,
> a non-nullable type on the right hand side, and return a non-nullable type.

Not exactly. It should accept both nullable and non-nullable on the right hand side, but the whole expression's type should mirror it.
Comment 2 Sam 2010-02-28 01:13:20 UTC
That makes sense now that I think of it
Comment 3 Marc-Andre Lureau 2010-03-11 23:45:27 UTC
Created attachment 155902 [details] [review]
Make right type dominate in ?? operator
Comment 4 Jürg Billeter 2010-03-13 16:52:25 UTC
Thanks for the patch. However, this is not completely correct as the type of the left and the type of the right expression may differ in more than just the nullable flag.

If the right expression is compatible to the type of the left expression, the type of the left expression should be used (as in master) with the exception that the nullable flag needs to be copied from the type of the right expression. Otherwise, the type of the right expression should be used (as in your patch).
Comment 5 Marc-Andre Lureau 2010-03-17 20:48:33 UTC
(In reply to comment #4)
> Thanks for the patch. However, this is not completely correct as the type of
> the left and the type of the right expression may differ in more than just the
> nullable flag.
> 
> If the right expression is compatible to the type of the left expression, the

we can assume it is, since the created assignment is checked.
 
> type of the left expression should be used (as in master) with the exception
> that the nullable flag needs to be copied from the type of the right
> expression. Otherwise, the type of the right expression should be used (as in
> your patch).

why should left type dominate over right type? I assumed that would should change since right and left are comparable (again previously created and checked expression) 

That's why I just decided to do this simple patch, and I believe it is still enough, although the error message might not be clear:

 611223.vala:12.28-12.29: error: Assignment: Cannot convert from `Obj?' to `Foo?'
	Obj non_nullable = foo ?? nn;
Comment 6 Sam 2010-06-08 23:51:09 UTC
Still exists in valac 0.9.1
Comment 7 Sam 2010-10-02 02:56:57 UTC
Still exists in valac 0.10
Comment 8 Al Thomas 2017-04-11 16:16:33 UTC
*** Bug 729488 has been marked as a duplicate of this bug. ***
Comment 9 Marvin W 2017-04-11 19:29:23 UTC
Created attachment 349694 [details] [review]
Fix + test-case

Note: to be able to add a test-case for this bug i added the possibility to use some valac flags for a test group. I am not very used to invoking tests from automake, so you might want to revise that (IMHO the test code is not very pretty anyway)
Comment 10 Rico Tzschichholz 2017-04-17 10:46:38 UTC
commit 50748111d26d839cb8244e1bfc0c6924305a90b1
Author: Marvin W <git@larma.de>
Date:   Tue Apr 11 17:19:58 2017 +0200

    vala: Handle non-null in coalescing expression
    
commit 2637bc5499279f8a49a47a7f2a3bf41e55db16a3
Author: Marvin W <git@larma.de>
Date:   Tue Apr 11 17:19:58 2017 +0200

    testrunner: Respect given VALAFLAGS