Skip to content

fix: closure's input type shouldn't be inherited from scope - #18540

Merged
Bahex merged 3 commits into
nushell:mainfrom
Bahex:push-qvqnkvzttmko
Jul 7, 2026
Merged

Bahex merged 3 commits into
nushell:mainfrom
Bahex:push-qvqnkvzttmko

Conversation

@Bahex

@Bahex Bahex commented Jul 7, 2026

Copy link
Copy Markdown
Member

User-facing changes (Release notes)

Closure's input type is not inherited from the surrounding scope

With last release, pipeline input type and how it affects various expressions are being tracked in a lot more cases.

In fact, at least one too many:

def mk-add-suffix [suffix: string]: nothing -> closure {
	{|| $in ++ $suffix }
}
Error: nu::parser::operator_unsupported_type

  × The '++' operator does not work on values of type 'nothing'.
   ╭─[repl_entry #1:2:6]
 1 │ def mk-add-suffix [suffix: string]: nothing -> closure {
 2 │     {|| $in ++ $suffix }
   ·         ─┬─ ─┬
   ·          │   ╰── does not support 'nothing'
   ·          ╰── nothing
 3 │ }
   ╰────

This is now fixed, and closures' input type will be inferred as any, the way it was before 0.114.0.

@Bahex Bahex added A:type-system Problems or features related to nushell's type system notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes A:closures Issues related to closures labels Jul 7, 2026
@github-actions github-actions Bot added the A:parser Issues related to parsing label Jul 7, 2026

@WindSoilder WindSoilder left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It breaks tests for the following code:

def only-nothing []: nothing -> string { "hello" }
def foo []: int -> any { let x = only-nothing; $x + 1 }

But after investigating the new error message, I think the new one is better.

Old

def only-nothing []: nothing -> string { "hello" }
def foo []: int -> any { let x = only-nothing; $x + 1 }
Error: nu::parser::input_type_mismatch

  × Command does not support int input.
   ╭─[repl_entry #1:2:34]
 1 │ def only-nothing []: nothing -> string { "hello" }
 2 │ def foo []: int -> any { let x = only-nothing; $x + 1 }
   ·                                  ──────┬─────
   ·                                        ╰── command doesn't support int input
   ╰────

New

def only-nothing []: nothing -> string { "hello" }
def foo []: int -> any { let x = only-nothing; $x + 1 }
Error: nu::parser::operator_incompatible_types

  × Types 'string' and 'int' are not compatible for the '+' operator.
   ╭─[repl_entry #5:2:48]
 1 │ def only-nothing []: nothing -> string { "hello" }
 2 │ def foo []: int -> any { let x = only-nothing; $x + 1 }
   ·                                                ─┬ ┬ ┬
   ·                                                 │ │ ╰── int
   ·                                                 │ ╰── does not operate between 'string' and 'int'
   ·                                                 ╰── string
   ╰────

@Bahex

Bahex commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@WindSoilder That's actually a regression the initial fix caused, it would have basically rolled back signature I/O based def body type checking and inference.

def bodies are apparently parsed as closures, which is a hack to avoid capturing mutable variables. Fixing that properly may require a big refactor so the latest commit itself is a hack to work around the existing one.

@Bahex
Bahex merged commit 6582932 into nushell:main Jul 7, 2026
17 checks passed
@github-actions github-actions Bot added this to the v0.115.0 milestone Jul 7, 2026
@Bahex Bahex linked an issue Jul 10, 2026 that may be closed by this pull request
@cptpiepmatz cptpiepmatz modified the milestones: v0.115.0, v0.114.1 Jul 11, 2026
@Bahex
Bahex deleted the push-qvqnkvzttmko branch July 28, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:closures Issues related to closures A:parser Issues related to parsing A:type-system Problems or features related to nushell's type system notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

closure's input type is inherited from the surrounding block

3 participants