Skip to content
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

Nil-coalescing operators #875

Open
pbdot opened this issue Dec 14, 2024 · 1 comment
Open

Nil-coalescing operators #875

pbdot opened this issue Dec 14, 2024 · 1 comment
Labels
feature request New feature or request nil

Comments

@pbdot
Copy link

pbdot commented Dec 14, 2024

Since every value can also be nil and we can also be explicit:

global type Trace = record
    ent: Entity | nil
end

It would very nice to be able to:

if trace.ent?.name then
end

... and if we know valid:

local name: string =  trace.ent!.name

Coming from TypeScript the "or" operator didn't occur to me, and not sure if any value in nullish coalescing

local ent = trace.ent ?? world;
@hishamhm hishamhm added the feature request New feature or request label Dec 18, 2024
@hishamhm
Copy link
Member

As long as every type contains nil, I don't think "being explicit" is a good idea there, because it gives the wrong impression to readers that T and T | nil are different things.

trace.ent?.name

Nil-coalescing operators would be nice, I'd like to have them, but implementing them properly would change the code generation a lot. So not a simple task!

@pbdot pbdot changed the title Optional property accesses and nullish coalescing operator Nil-coalescing operators Dec 18, 2024
@hishamhm hishamhm added the nil label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request nil
Projects
None yet
Development

No branches or pull requests

2 participants