diff --git a/src/core/Main.pm6 b/src/core/Main.pm6 index 3bf55a00106..388bdb34a51 100644 --- a/src/core/Main.pm6 +++ b/src/core/Main.pm6 @@ -125,14 +125,30 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) { ?? "-e '...'" !! strip_path_prefix($prog-name); + # return the Cool constant if the post_constraints of a Parameter is + # a single Cool constant, else Nil + sub cool_constant(Parameter:D $p) { + nqp::not_i( + nqp::isnull( + (my \post_constraints := + nqp::getattr($p,Parameter,'@!post_constraints')) + ) + ) && nqp::elems(post_constraints) == 1 + && nqp::istype((my \value := nqp::atpos(post_constraints,0)),Cool) + ?? value + !! Nil + } + # Select candidates for which to create USAGE string sub usage-candidates($capture) { my @candidates = &main.candidates.grep: { !.?is-hidden-from-USAGE } if $capture.list -> @positionals { my $first := @positionals[0]; if @candidates.grep: -> $sub { - if $sub.signature.params[0].cool_constant -> $literal { - $literal.ACCEPTS($first) + if $sub.signature.params[0] -> $param { + if cool_constant($param) -> $literal { + $literal.ACCEPTS($first) + } } } -> @candos { return @candos; diff --git a/src/core/Parameter.pm6 b/src/core/Parameter.pm6 index 544d4dd6741..8477cd1c6d9 100644 --- a/src/core/Parameter.pm6 +++ b/src/core/Parameter.pm6 @@ -630,15 +630,6 @@ my class Parameter { # declared in BOOTSTRAP $perl ~ $rest; } - # return the cool constant if the post_constraint is a single Cool constant - method cool_constant() { - nqp::not_i(nqp::isnull(@!post_constraints)) - && nqp::elems(@!post_constraints) == 1 - && nqp::istype((my \value := nqp::atpos(@!post_constraints,0)),Cool) - ?? value - !! Nil - } - method sub_signature(Parameter:D:) { nqp::isnull($!sub_signature) ?? Any !! $!sub_signature }