rakudo icon indicating copy to clipboard operation
rakudo copied to clipboard

Using named array as a parameter in a MAIN sub changes the other parameters to type Array

Open demanuel opened this issue 3 years ago • 1 comments

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.

demanuel avatar Jan 16 '23 18:01 demanuel

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.

ab5tract avatar May 16 '24 14:05 ab5tract

This behaviour is caused by the following logic:

  1. take the given arguments, process them and convert them into a Capture
  2. run this Capture against the MAIN candidates
  3. if this fails, create a new Capture with all of the arguments that are not Positional to a Array`.
  4. run this adapted Capture against the MAIN candidates, and if that works out, call the appropriate candidate with this adapted Capture.

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).

lizmat avatar Feb 16 '25 18:02 lizmat

Tests added with https://github.com/Raku/roast/commit/41602e2493

lizmat avatar Feb 16 '25 20:02 lizmat