Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mogrify adverb slice logic into an Exception
So that we can properly test for them.  This should probably be
run at compile time somehow, but for now runtime will do.
  • Loading branch information
lizmat committed Jul 6, 2015
1 parent f2d9c9f commit 626f906
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/core/Any.pm
@@ -1,6 +1,7 @@
my class MapIter { ... }
my class Pair { ... }
my class Range { ... }
my class X::Adverb::Slice { ... }
my class X::Bind { ... }
my class X::Bind::Slice { ... }
my class X::Bind::ZenSlice { ... }
Expand Down Expand Up @@ -830,8 +831,6 @@ sub RWPAIR(\k, \v) { # internal fast pair creation
p
}

sub OBJECT_HUH(\SELF) { try { SELF.VAR.name } // SELF.WHAT.perl }

sub SLICE_HUH(\SELF, @nogo, %d, %adv) {
@nogo.unshift('delete') # recover any :delete if necessary
if @nogo && @nogo[0] ne 'delete' && %adv.EXISTS-KEY('delete');
Expand All @@ -842,15 +841,11 @@ sub SLICE_HUH(\SELF, @nogo, %d, %adv) {
}
}

if %d.elems -> $elems {
$elems > 1
?? fail "$elems unexpected named arguments (%d.keys.join(', ')) passed to {OBJECT_HUH(SELF)}"
!! fail "Unexpected named argument '%d.keys.[0]' passed to {OBJECT_HUH(SELF)}";
}

else {
fail "Unsupported combination of named arguments (@nogo.join(', ')) passed to {OBJECT_HUH(SELF)}";
}
fail X::Adverb::Slice.new(
:what(try { SELF.VAR.name } // SELF.WHAT.perl),
:unexpected(%d.keys.sort),
:@nogo,
);
} #SLICE_HUH

sub DELETEKEY(Mu \d, str $key) {
Expand Down
19 changes: 19 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -926,6 +926,25 @@ my class X::Method::Private::Unqualified does X::Comp {
}
}

my class X::Adverb::Slice is Exception {
has $.what;
has @.unexpected;
has @.nogo;
method message {
my $text = '';
if @!unexpected.elems -> $elems {
$text = $elems > 1
?? "$elems unexpected adverbs (@!unexpected[])"
!! "Unexpected adverb '@!unexpected[0]'"
}
if @!nogo {
$text ~= $text ?? " and u" !! "U";
$text ~= "nsupported combination of adverbs (@!nogo[])";
}
$text ~ " passed to slice on $!what";
}
}

my class X::Bind is Exception {
has $.target;
method message() {
Expand Down

0 comments on commit 626f906

Please sign in to comment.