Skip to content

closure's input type is inherited from the surrounding block #18564

Closed

Description

@Bahex

Tip

Reported by @jeromed on discord

Hi all! I have seen the new typing system which looks really interesting, and I might have felt on a corner case

Error: nu::parser::operator_unsupported_type

  × The '+' operator does not work on values of type 'nothing'.
    ╭─[/home/.../Documents/server-check.nu:20:20]
 19 │ def run_check [server: string, --prev-id: oneof<string, nothing>]: nothing -> oneof<string, nothing> {
 20 │   let kb_to_fs = { $in + "kB" | into filesize }
    ·                    ─┬─ ┬
    ·                     │  ╰── does not support 'nothing'
    ·                     ╰── nothing
 21 │ 
    ╰────

This is a closure inside a function. Replacing the closure by a standalone function fixed the issue but I wanted to report it to check with you if it is the expected behavior.
A few thoughts:

  • may $in incorrectly refer to run_check's $in which is nothing?
  • is $in unknown at this point so the parser assumes nothing type? I guess it assumes any type IIUC the release notes.
  • can it infer a type depending on the usage of the closure? (It is a string coming from a long pipeline so I'm not sure what the parser sees at closure call site)

Activity

  1. added theissue type on Jul 10, 2026
  2. added
    A:type-system
    on Jul 10, 2026
  3. added
    A:closures
    on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:closuresA:type-system

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions