rakudo
rakudo copied to clipboard
Using named array as a parameter in a MAIN sub changes the other parameters to type Array
demanuel@archlinux ~> cat test.raku
sub MAIN( :$option, :@tag) { say $option.WHAT;}
demanuel@archlinux ~> raku test.raku --option --tag=name1
(Array)
demanuel@archlinux ~> raku test.raku --option --tag=name1 --tag=name2
(Bool)
demanuel@archlinux ~>
Expected Behavior
In the execution the parameter $option should be a Bool, like in the second invocation
> uname -a
Linux archlinux 6.1.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 14 Jan 2023 13:09:35 +0000 x86_64 GNU/Linux
> raku -v
Welcome to Rakudoâ„¢ v2022.12-985-g05cfed1b0.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.12-14-gebefe2618.
This is still happening as of
> ./rakudo-m -v
Welcome to Rakudoâ„¢ v2024.04-92-g24057e69c.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2024.04-6-g84121f0de.
This behaviour is caused by the following logic:
- take the given arguments, process them and convert them into a
Capture - run this
Captureagainst theMAINcandidates - if this fails, create a new
Capturewith all of the arguments that are notPositional to aArray`. - run this adapted
Captureagainst theMAINcandidates, and if that works out, call the appropriate candidate with this adaptedCapture.
This explains why in the --option --tag=name1 example, the option value appears as an Array, because it was matched against the adapted Capture. And in the --option --tag=name1 --tag=name2exampler, it's just aBool(because the originalCapture` already found a candidate).
Tests added with https://github.com/Raku/roast/commit/41602e2493