/
lexical-multis.t
62 lines (50 loc) 路 1.75 KB
/
lexical-multis.t
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use v6;
use Test;
plan 15;
# basic test that multi is lexical
{
{
my multi foo() { 42 }
is(foo(), 42, 'can call lexically scoped multi');
}
eval_dies_ok(q{ foo() }, 'lexical multi not callable outside of lexical scope');
}
# test that lexical multis in inner scopes add to those in outer scopes
{
{
my multi bar() { 1 }
{
my multi bar($x) { 2 } #OK not used
is(bar(), 1, 'outer lexical multi callable');
is(bar('syr'), 2, 'new inner lexical multi callable');
}
is(bar(), 1, 'in outer scope, can call the multi that is in scope');
dies_ok { eval("bar('pivo')") }, 'multi variant from inner scope not callable in outer';
}
dies_ok { eval q{ bar() }}, 'no multi variants callable outside of lexical scope';
dies_ok { eval q{ bar('kava')} }, 'no multi variants callable outside of lexical scope';
}
# an inner multi with a signature matching an outer will hide it
{
my multi baz() { 1 }
{
my multi baz() { 2 } #OK not used
#?rakudo todo 'lexical scope as tie breaker'
lives_ok({ baz() }, 'inner multi conflicts with outer one');
}
is(baz(), 1, 'in outer scope, no inner multi, so no conflict');
}
# lexical multi can add to package multi if no outer lexical ones
multi waz() { 1 }
{
my multi waz($x) { 2 } #OK not used
is(waz(), 1, 'got multi from package');
is(waz('slon'), 2, 'lexical multi also callable');
}
is(waz(), 1, 'multi from package still callable outside the inner scope...');
dies_ok { eval("waz('vtak')") }, '...but lexical multi no longer callable';
# RT #78208
{
dies_ok { multi foo() { }; multi foo($x) { }; +&foo }, 'RT #78208'
}
# vim: ft=perl6 :