Skip to content

fix(parser): try string last in oneof so oneof<string, list<string>> parses [a b] as a list - #19238

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_oneof_string_order
Oct 16, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_oneof_string_order

Conversation

@fdncred

@fdncred fdncred commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

The order of the types in a oneof changed what a literal argument parsed as:

> def show [x: oneof<string, list<string>>] { $x | describe }
> show [foo bar]
string
> def show [x: oneof<list<string>, string>] { $x | describe }
> show [foo bar]
list<string>

parse_oneof returns the first shape that parses without error, and the string shape accepts nearly any single token as a bare word. With string listed first, every type after it was unreachable from a literal:

oneof<string, X> literal parsed as (before) parsed as (after)
list<string> [foo bar] "[foo bar]" [foo, bar]
table [[a]; [1]] "[[a]; [1]]" table<a: int>
int 5 "5" 5
number 1.5 "1.5" 1.5
duration 5sec "5sec" 5sec
filesize 5kb "5kb" 5kb
range 1..5 "1..5" 1..5
datetime 2024-01-01 "2024-01-01" 2024-01-01
binary 0x[ff] "0x[ff]" 0x[FF]

oneof<path, list<path>> and oneof<glob, list<glob>> had the same problem, and so did parameter defaults and list elements: [x: oneof<string, int> = 5] defaulted to the string "5", and list<oneof<string, int>> parsed [1 a] as ["1", a]. Both now give ints. The type check doesn't depend on order, so let x = [foo bar]; show $x already passed a list.

User-facing changes (Release notes)

oneof literals prefer matching types over strings

In oneof<...> parameter types, string, path, directory, glob, cell-path, external_arg and any no longer claim a literal that another listed type matches, regardless of their order. oneof<string, list<string>> now parses [foo bar] as a list, and oneof<string, int> parses 5 as an integer rather than a string. This also fixes literal parameter defaults and list elements: [x: oneof<string, int> = 5] now defaults to an integer, and list<oneof<string, int>> parses [1 a] with an integer first element.

Quote literals when you need their original text. With oneof<string, int>, 007 arrives as 7 and 0x10 as 16; with oneof<string, number>, 1.10 arrives as 1.1 and nan as a float. With oneof<string, list<string>>, [0-9] arrives as the list ["0-9"]. This also applies to extern parameters, which pass the converted value to the external command.

Bare words that no other listed type matches still parse as strings. Arguments starting with $, ( or { and parameters declared as plain string are unchanged.

Additional notes

closes #16445

@github-actions github-actions Bot added the A:parser Issues related to parsing label Oct 14, 2026
@fdncred
fdncred merged commit 07b01e2 into nushell:main Oct 16, 2026
12 checks passed
@fdncred
fdncred deleted the fix_oneof_string_order branch October 16, 2026 11:53
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 16, 2026
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing 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.

oneof<> parameter parsing with lists is incorrect

1 participant