Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (21 sloc) 0.951 kb
use v6;
use Test;
plan 6;
# L<S12/Candidate Tiebreaking/"only candidates marked with the default
# trait">
class Something {
multi method doit(Int $x) { 2 * $x };
multi method doit(Int $x) is default { 3 * $x };
}
my $obj = Something.new();
lives_ok { $obj.doit(3) }, "'is default' trait makes otherwise ambiguous method dispatch live";
is $obj.doit(3), 9, "'is default' trait tie-breaks on method dispatch";
multi sub doit_sub(Int $x) { 2 * $x };
multi sub doit_sub(Int $x) is default { 3 * $x };
lives_ok { doit_sub(3) }, "'is default' trait makes otherwise ambiguous method dispatch live";
is doit_sub(3), 9, "'is default' trait on subs";
multi sub slurpy() is default { return 'a' };
multi sub slurpy(*@args) { return 'b' }; #OK not used
is slurpy(2), 'b', 'basic sanity with arity based dispatch and slurpies';
is slurpy(), 'a', '"is default" trait wins against empty slurpy param';
# vim: ft=perl6
Jump to Line
Something went wrong with that request. Please try again.