Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add types to signature and make multi
Fix several cases where Type.method would give a "cannot access attribute in
a type object": should that happen now, it should give you a "cannot find
candidate", or should just work.
  • Loading branch information
lizmat committed Dec 20, 2014
1 parent 23413d3 commit a00041d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/core/List.pm
Expand Up @@ -45,11 +45,11 @@ my class List does Positional { # declared in BOOTSTRAP
nqp::p6list($args, self.WHAT, Mu);
}

method Bool() { self.gimme(1).Bool }
method Int() { self.elems }
method end() { self.elems - 1 }
multi method Numeric(List:D:) { self.elems }
multi method Str(List:D:) { self.join(' ') }
multi method Bool(List:D:) { self.gimme(1).Bool }
multi method Int(List:D:) { self.elems }
multi method end(List:D:) { self.elems - 1 }
multi method Numeric(List:D:) { self.elems }
multi method Str(List:D:) { self.join(' ') }

# Pretend we're a Match assuming we're a list of Matches
method to() { self.elems ?? self[self.end].to !! Nil }
Expand Down
14 changes: 3 additions & 11 deletions src/core/OS.pm
Expand Up @@ -16,17 +16,9 @@ my class Proc::Status {
$!exit = $new_status +> 8;
$!signal = $new_status +& 0xFF;
}
multi method status() {
($!exit +< 8) +| $!signal
}

method Numeric {
$!exit
}

method Bool {
$!exit == 0
}
multi method status(Proc::Status:D:) { ($!exit +< 8) +| $!signal }
multi method Numeric(Proc::Status:D:) { $!exit }
multi method Bool(Proc::Status:D:) { $!exit == 0 }
}

# vim: ft=perl6 expandtab sw=4
4 changes: 2 additions & 2 deletions src/core/Setty.pm
Expand Up @@ -13,9 +13,9 @@ my role Setty does QuantHash {
method exists_key($k --> Bool) {
so ( %!elems && nqp::existskey(%!elems, nqp::unbox_s($k.WHICH)) );
}
method Bool { %!elems.Bool }
multi method Bool(Setty:D:) { %!elems.Bool }

method hash(--> Hash) {
multi method hash(Setty:D: --> Hash) {
my %e;
%e{$_} = True for %!elems.values;
%e;
Expand Down
11 changes: 3 additions & 8 deletions src/core/StrDistance.pm
Expand Up @@ -3,15 +3,10 @@ my class StrDistance is Cool {
has Str $.after;
has Int $!distance;

method Bool() {
$.before ne $.after
}

method Numeric() {
self.Int
}
multi method Bool(StrDistance:D:) { $.before ne $.after }
multi method Numeric(StrDistance:D:) { self.Int }

method Int() {
multi method Int(StrDistance:D:) {
$!distance //= do {
my @s = *, $.before.comb;
my @t = *, $.after.comb;
Expand Down

0 comments on commit a00041d

Please sign in to comment.