New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for the null coalescing operator ?? #809

Merged
merged 1 commit into from Aug 21, 2014

Conversation

Projects
None yet
2 participants
@alexnask
Collaborator

alexnask commented Aug 21, 2014

No description provided.

alexnask added a commit that referenced this pull request Aug 21, 2014

Merge pull request #809 from shamanas/master
Added support for the null coalescing operator ??

Closes #627

@alexnask alexnask merged commit c10f431 into ooc-lang:master Aug 21, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@davidhesselbom

This comment has been minimized.

Contributor

davidhesselbom commented Oct 28, 2015

@alexnask

This comment has been minimized.

@davidhesselbom

This comment has been minimized.

Contributor

davidhesselbom commented Oct 29, 2015

Wait, it was added in... um. I don't know what I was thinking, this is over a year old and so is the commit in NagaQueen. Forget I said anything :P

@alexnask

This comment has been minimized.

Collaborator

alexnask commented Oct 29, 2015

Haha no worries, I missed the Nagaqueen.c diff too for a bit and was wondering if it was pushed before it got implemented in rock ^^

@alexnask

This comment has been minimized.

Collaborator

alexnask commented Oct 29, 2015

@davidhesselbom I think there is a double evaluation bug with it still, I'll take a look at it right now

(I think I naively translated a ?? b to a != null ? a : b without taking the side effects of a into account)

@davidhesselbom

This comment has been minimized.

Contributor

davidhesselbom commented Oct 29, 2015

You did...

honk: func -> Bool { println("honk"); true }
toot := honk() ?? false

prints

honk
honk

but it should only print the word once.

@davidhesselbom

This comment has been minimized.

Contributor

davidhesselbom commented Oct 29, 2015

Also, your test includes this line:

if ((1 ?? 2 ?? 3) != 3)

which gives me the following warnings:

test.ooc: In function ‘test_test_load’:
test.ooc:7:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
 if ((1 ?? 2 ?? 3) != 3)
                   ^
test.ooc:7:55: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
 if ((1 ?? 2 ?? 3) != 3)
                                                       ^

@alexnask

This comment has been minimized.

Collaborator

alexnask commented Oct 29, 2015

Huh, interesting how the operator works with bool too, probably because I actually translate to a ? a : b, I'm not sure if even that is intended.

Translating to

a_temp : typeof(a)

... (a_temp = a, a_temp ? a_temp : b) ...

Should do the trick, grabbing a coffee and going to town :)

Edit: actually, the != null comparison is there, your honk example compares a Bool to a Pointer, which apparently passes right through rock, and true == 1 != null, so it seems to work with bools too :P

@alexnask

This comment has been minimized.

Collaborator

alexnask commented Oct 29, 2015

I don't get warnings on my test but I could see how you would if you ignore the overload

operator ?? (l, r: Int) -> Int { r }

In which case you are comparing integers to null, thus "cast from pointer to integer of different size"

@davidhesselbom

This comment has been minimized.

Contributor

davidhesselbom commented Oct 29, 2015

Ah, yes, I did, I just took that one line from the test file. That explains it.

@alexnask

This comment has been minimized.

Collaborator

alexnask commented Oct 29, 2015

Should be somewhat better to use now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment