Repository navigation
fix(parser): try string last in oneof so oneof<string, list<string>> parses [a b] as a list - #19238
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The order of the types in a
oneofchanged what a literal argument parsed as:parse_oneofreturns the first shape that parses without error, and thestringshape accepts nearly any single token as a bare word. Withstringlisted first, every type after it was unreachable from a literal:oneof<string, X>list<string>[foo bar]"[foo bar]"[foo, bar]table[[a]; [1]]"[[a]; [1]]"table<a: int>int5"5"5number1.5"1.5"1.5duration5sec"5sec"5secfilesize5kb"5kb"5kbrange1..5"1..5"1..5datetime2024-01-01"2024-01-01"2024-01-01binary0x[ff]"0x[ff]"0x[FF]oneof<path, list<path>>andoneof<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", andlist<oneof<string, int>>parsed[1 a]as["1", a]. Both now give ints. The type check doesn't depend on order, solet x = [foo bar]; show $xalready passed a list.User-facing changes (Release notes)
oneofliterals prefer matching types over stringsIn
oneof<...>parameter types,string,path,directory,glob,cell-path,external_argandanyno longer claim a literal that another listed type matches, regardless of their order.oneof<string, list<string>>now parses[foo bar]as a list, andoneof<string, int>parses5as 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, andlist<oneof<string, int>>parses[1 a]with an integer first element.Quote literals when you need their original text. With
oneof<string, int>,007arrives as7and0x10as16; withoneof<string, number>,1.10arrives as1.1andnanas a float. Withoneof<string, list<string>>,[0-9]arrives as the list["0-9"]. This also applies toexternparameters, 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 plainstringare unchanged.Additional notes
closes #16445