-
Notifications
You must be signed in to change notification settings - Fork 192
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
"unless" conditional with assignment fails to compile #251
Comments
|
but that's not what it's supposed to compile to. if x = true
dongs! compiles to do
local x = true
if x then
return dongs()
end
end
I'll leave it to you to figure out how it'd work with |
Sorry. I didn't realize |
What scenario would you like to use this syntax? When you use if x = something!
-- x is only available in this scope When using |
The variable may be declared beforehand, putting it in a higher scope. local x
unless x = tryTheOneThing!
x = assert tryTheOtherThing!, "We're doomed!" |
Just to add an example, now that I think of it. local lfs
unless lfs = tryrequire "lfs"
lfs = require "syscall.lfs" Imagine that for this scenario tryrequire is a require() that doesn't error but instead just returns false. |
In that scenario I think it makes more sense to write: lfs = tryrequire "lfs"
unless lfs
lfs = require "syscall.lfs" |
Well, that was a basic example. I'm certain there are better reasons for implementing this. |
Moonscript v0.4.0 fails to compile an assignment conditionals with the
unless
keyword (if
works).Minimal Sample:
Compiler errors out with:
Linter dies, too:
The reference manual doesn't explicitly state that
unless
in particular can be used with assignment, but as opposed toif not
there's no apparent reason why it shouldn't work.Even if it's not supposed to work, i suppose the compiler should die with a more helpful error message.
The text was updated successfully, but these errors were encountered: