Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b27262e7e8
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (23 sloc) 1.011 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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";
#?pugs todo
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';
#?pugs skip 'make todo? passes. untodo? fails.'
is slurpy(), 'a', '"is default" trait wins against empty slurpy param';

# vim: ft=perl6
Something went wrong with that request. Please try again.