Skip to content

Can't use a Nu script with strings starting with a number #8844

Closed

Description

@mksinicus

Describe the bug

It is now (after #8635) impossible to invoke a Nu script with an argument which is a string starting with a number.

Essentially same as #8788 but that issue was falsely closed.

How to reproduce

> cat foo.nu
#!/usr/bin/env nu
def main [s: string] {
  echo $s
}
> chmod +x foo.nu
> let s = '1bar'
> ./foo.nu $s        # gives the same error as below, omitted
> ./foo.nu $'"($s)"' # awful but expected to work, yet the error remains
Error: nu::parser::type_mismatch

  × Type mismatch during operation.
   ╭─[<commandline>:1:1]
 1 │ main 1bar
   ·      ───┬──
   ·         ╰── expected string, found number-like value (hint: use quotes or backticks)
   ╰────

Expected behavior

I expect at least the foo $'"($s)"' approach to work. Or even better we have #8635 reverted...

Making such functions a module should work, but not so optimal for invoking inside another script or module.

Screenshots

No response

Configuration

key value
version 0.78.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.68.1 (8460ca823 2023-03-20)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.68.1 (115f34552 2023-02-26)
build_time 2023-04-06 02:23:04 +08:00
build_rust_channel release
features default, zip
installed_plugins from eml, from ics, from ini, from vcf, query, query json, query web, query xml

Additional context

By the way this could have mingled with #7936, because foo $"''($str)''" prints 1bar, not '1bar'.

Activity

  1. added a commit that references this issue on Apr 11, 2023
    46dba88
  2. added a commit that references this issue on Apr 12, 2023
    2393d2e
  3. added this to the v0.79.0 milestone on Apr 12, 2023
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions