-
Notifications
You must be signed in to change notification settings - Fork 1.8k
error when a closure is used as def
body
#14311
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
Conversation
56beb98
to
53c997c
Compare
Sorry, this change will break the following code: mut x = 3
def a [] {
$x = 4
} It should raise error. |
Ah we definitely need a test for those scoping/mutability rules |
53c997c
to
d81048f
Compare
@WindSoilder good catch! I added a boolean field to |
…le (#14314) @sholderbach suggested that we need to have a test for a function can't use mutable variable. #14311 (comment) So this pr is going to add a case for it. --------- Co-authored-by: Stefan Holderbach <[email protected]>
d81048f
to
98f1309
Compare
Thanks! I think I get the idea behind these changes, but TBH I'm not sure if the solution is good. It seems too hacky. |
I also found it randomly break my script: export def main [word: string] {
if true {
return "aa"
} else {
# query from web
try {
let result = http get $"http://url" -m 4 | str length
$result
} catch {|e|
if true {
let spell_check = "a"
$spell_check
} else {
error make ($e | get raw)
}
}
}
} It gives me the following error:
|
Update: @WindSoilder that error should be fixed by #14420 That parse error seems to start with the if true { http get "" -m 4 } else { } # expected duration with valid units
if true { } else { http get "" -m 4 } # expected one of a list of accepted shapes: [Block, Expression] |
It's also a breaking change for plugins. That alone might call for a different approach. |
98f1309
to
d437ff9
Compare
where are we at on this? |
# User-Facing Changes `def` now errors instead of silently ignoring closure blocks: ```nushell > def foo [] {|bar| } Error: nu::parser::parse_mismatch × Parse mismatch during operation. ╭─[entry nushell#1:1:12] 1 │ def foo [] {|bar| } · ────┬─── · ╰── expected definition body { ... } ╰──── ```
I'll fix the conflict but don't know of a cleaner way to solve this without |
d437ff9
to
f844a3d
Compare
To be honest I still don't think it's the right way to go. Hopefully we can solve it in the new parser. |
Closes #9737
User-Facing Changes
def
now errors instead of silently ignoring closure blocks: