djinni-generator
djinni-generator copied to clipboard
Support for "null" in const values for optional
Hi,
We need investigate is the keyword "null" can be a correct value for optional.
Example:
foo_data = record {
label: optional<string>;
const empty: foo_data = {
label = null // obviously error as null Const null does not exist. but what can I use?
//label = “” // I can only do this
}
}
The expected result is generate a null value
depending of the language (the generator).
- In "C++" the "null" keyword need be "nullptr"
- In "C" the "null" keyword need be "NULL"
- In "Java" the "null" keyword need be "null"
- In "ObjC" the "null" keyword need be "nil"
- In "Python" the "null" keyword need be "None"
I think that null optional constants were intentionally never implemented because they seemed meaningless (why do you need a constant for null). Here's a comment in the test suite which suggests that: https://github.com/dropbox/djinni/blob/4f3aa6971b2b539cfadec4df2243a268651c4de3/test-suite/djinni/constants.djinni#L82
That being said, your example of a constant record, which contains an optional value, which happens to be null in the constant value (but non-null in other record values) does seem like a legitimate use case, so it may be worth implementing. Someone else gets to have the holy-war about whether it should be called "null" or "nil" or something else. :)
Hi,
Thanks @artwyman.
It need be called "null" that is more easy to read and understand by the users (nil is more used in objc, nullptr is used in cpp etc). So to be clear to the final user, the value need be called "null", as the word says and the suer don't need think "what it is".
So, i will keep it open to be implemented.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.