diff --git a/src/core/Main.pm6 b/src/core/Main.pm6 index 388bdb34a51..e0b535cbc08 100644 --- a/src/core/Main.pm6 +++ b/src/core/Main.pm6 @@ -266,6 +266,22 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) { False } + sub find-candidates($capture) { + &main + # Get a list of candidates that match according to the dispatcher + .cando($capture) + # Sort out all that would fail due to binding + .grep: { !has-unexpected-named-arguments(.signature, $capture.hash) } + } + + # turn scalar values of nameds into 1 element arrays, return new capture + sub scalars-into-arrays($capture) { + my %hash = $capture.hash.map: { + nqp::istype(.value,Positional) ?? $_ !! Pair.new(.key,[.value]) + } + Capture.new( :list($capture.list), :%hash) + } + # set up other new style dynamic variables my &*ARGS-TO-CAPTURE := &default-args-to-capture; my &*GENERATE-USAGE := &default-generate-usage; @@ -274,14 +290,17 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) { my $capture := args-to-capture(&main, @*ARGS); # Get a list of candidates that match according to the dispatcher - my @matching_candidates = &main.cando($capture); - - # Sort out all that would fail due to binding - @matching_candidates .= - grep: { !has-unexpected-named-arguments(.signature, $capture.hash) }; + my @candidates = find-candidates($capture); + if !@candidates { + my $alternate = scalars-into-arrays($capture); + if find-candidates($alternate) -> @alternates { + $capture := $alternate; + @candidates = @alternates; + } + } # If there are still some candidates left, try to dispatch to MAIN - if @matching_candidates { + if @candidates { if $in-as-argsfiles { my $*ARGFILES := IO::ArgFiles.new: (my $in := $*IN), :nl-in($in.nl-in), :chomp($in.chomp), :encoding($in.encoding),