Skip to content
Permalink
Browse files

Tweaks on Parameter.new

- added "exclude" parameter
  If set to a True value, then the parameter will be excluded from dispatch
  (aka, it will introduce a ";;" in the Signature of which the Parameter is
  to be a part)

- don't normalize types to string
  This caused issues with using imported constants such as NativeCall.  So
  the logic is now: if the value is a type object, it will be used.  If it
  is a concrete object and **not** a Str, the associated type object will be
  used.  Otherwise a lookup of the string will be done.
  • Loading branch information...
lizmat committed Jan 11, 2019
1 parent 3d3578b commit c4723cbafa9171cabbf65b880a7ae60ab2e85321
Showing with 20 additions and 12 deletions.
  1. +20 −12 src/core/Parameter.pm6
@@ -97,6 +97,7 @@ my class Parameter { # declared in BOOTSTRAP
Bool:D :$is_copy = False,
Bool:D :$is_rw = False,
Bool:D :$is_raw = False,
Bool:D :$exclude = False,
# type / default / where captured through %_
) {

@@ -165,19 +166,26 @@ my class Parameter { # declared in BOOTSTRAP
}

if %_.EXISTS-KEY('type') {
my $type = %_.AT-KEY('type');
$type = $type.^name
unless $type.DEFINITE && nqp::istype($type,Str);

if $type.ends-with(Q/)/) {
my $start = $type.index(Q/(/);
$!nominal_type :=
str-to-type($type.substr($start + 1, *-1), my $);
$!coerce_type :=
str-to-type($type.substr(0, $start), $flags);
my $type := %_.AT-KEY('type');
if $type.DEFINITE {
if nqp::istype($type,Str) {
if $type.ends-with(Q/)/) {
my $start = $type.index(Q/(/);
$!nominal_type :=
str-to-type($type.substr($start + 1, *-1), my $);
$!coerce_type :=
str-to-type($type.substr(0, $start), $flags);
}
else {
$!nominal_type := str-to-type($type, $flags)
}
}
else {
$!nominal_type := $type.WHAT;
}
}
else {
$!nominal_type := str-to-type($type, $flags)
$!nominal_type := $type;
}
}
else {
@@ -209,7 +217,7 @@ my class Parameter { # declared in BOOTSTRAP
$flags +|= $SIG_ELEM_IS_OPTIONAL if $optional;
}

$flags +|= $SIG_ELEM_MULTI_INVOCANT; # seems to be needed always??
$flags +|= $SIG_ELEM_MULTI_INVOCANT unless $exclude;
$flags +|= $SIG_ELEM_IS_COPY if $is_copy;
$flags +|= $SIG_ELEM_IS_RW if $is_rw;
$flags +|= $SIG_ELEM_IS_RAW if $is_raw;

0 comments on commit c4723cb

Please sign in to comment.
You can’t perform that action at this time.