Skip to content

allow define it as a variable inside closure#12888

Merged
IanManske merged 2 commits intonushell:mainfrom
WindSoilder:do_with_it
May 17, 2024
Merged

allow define it as a variable inside closure#12888
IanManske merged 2 commits intonushell:mainfrom
WindSoilder:do_with_it

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

Description

Fixes: #12690

The issue is happened after #12056 is merged. It will raise error if user doesn't supply required parameter when run closure with do.
And parser adds a $it parameter when parsing closure or block expression.

I believe the previous behavior is because we allow such syntax on previous version(0.44):

let x = { print $it }

But it's no longer allowed after 0.60. So I think they can be removed.

User-Facing Changes

let tmp = {
  let it = 42
  print $it
}

do -c $tmp

should be possible again.

Tests + Formatting

Added 1 test

Copy link
Copy Markdown
Member

@IanManske IanManske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@IanManske IanManske merged commit 8adf340 into nushell:main May 17, 2024
@hustcer hustcer added this to the v0.94.0 milestone May 17, 2024
FilipAndersson245 pushed a commit to FilipAndersson245/nushell that referenced this pull request May 18, 2024
# Description
Fixes: nushell#12690 

The issue is happened after
nushell#12056 is merged. It will raise
error if user doesn't supply required parameter when run closure with
do.
And parser adds a `$it` parameter when parsing closure or block
expression.

I believe the previous behavior is because we allow such syntax on
previous version(0.44):
```nushell
let x = { print $it }
```
But it's no longer allowed after 0.60.  So I think they can be removed.

# User-Facing Changes
```nushell
let tmp = {
  let it = 42
  print $it
}

do -c $tmp
```
should be possible again.

# Tests + Formatting
Added 1 test
@WindSoilder WindSoilder deleted the do_with_it branch May 23, 2024 02:57
@IanManske IanManske added the notes:fixes Include the release notes summary in the "Bug fixes" section label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Include the release notes summary in the "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

it is somehow a special variable in closure (since 0.92)

3 participants