summaryrefslogtreecommitdiff
path: root/t/lib/croak/class
blob: 48a744b511aa082743b62832830b04772ab44115 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
__END__
# Method calls on no args
no warnings 'experimental::class';
use feature 'class';
class XXX { method m { } }
XXX::m()
EXPECT
Cannot invoke method "m" on a non-instance at - line 5.
########
# Method calls on non-ref
no warnings 'experimental::class';
use feature 'class';
class XXX { method m { } }
XXX::m(123)
EXPECT
Cannot invoke method "m" on a non-instance at - line 5.
########
# Method calls on non-object
no warnings 'experimental::class';
use feature 'class';
class XXX { method m { } }
XXX::m([])
EXPECT
Cannot invoke method "m" on a non-instance at - line 5.
########
# Method calls from a different class
no warnings 'experimental::class';
use feature 'class';
class XXX { method m { } }
class YYY {}
YYY->new->XXX::m();
EXPECT
Cannot invoke a method of "XXX" on an instance of "YYY" at - line 6.
########
no warnings 'experimental::class';
use feature 'class';
class XXX {}
bless [], "XXX";
EXPECT
Attempt to bless into a class at - line 4.
########
no warnings 'experimental::class';
use feature 'class';
class XXX {}
bless(XXX->new, "main");
EXPECT
Can't bless an object reference at - line 4.
########
no warnings 'experimental::class';
use feature 'class';
class XXX { field $zz; $zz = 123; }
EXPECT
Field $zz is not accessible outside a method at - line 3.
########
no warnings 'experimental::class';
use feature 'class';
class XXX { field $x; sub f { print $x } }
EXPECT
Field $x is not accessible outside a method at - line 3.
########
no warnings 'experimental::class';
use feature 'class';
class XXX {
  field $x;
  class YYY { method m { print $x } }
}
EXPECT
Field $x of "XXX" is not accessible in a method of "YYY" at - line 5.
########
no warnings 'experimental::class';
use feature 'class';
class XXX {}
class XXX {}
EXPECT
Cannot reopen existing class "XXX" at - line 4.
########
no warnings 'experimental::class';
use feature 'class';
class XXX {}
push @XXX::ISA, q(Another);
EXPECT
Modification of a read-only value attempted at - line 4.
########
no warnings 'experimental::class';
use feature 'class';
BEGIN { push @XXX::ISA, q(Another); }
class XXX {}
EXPECT
Cannot create class XXX as it already has a non-empty @ISA at - line 4.
########
use strict;
no warnings 'experimental::class';
use feature 'class';
class XXX {
  field $x = $self + 1;
}
EXPECT
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at - line 5.
Execution of - aborted due to compilation errors.
########
use strict;
no warnings 'experimental::class';
use feature 'class';
class XXX {
  field $x = last;
}
EXPECT
Can't "last" out of field initialiser expression at - line 5.
########
use strict;
no warnings 'experimental::class';
use feature 'class';
class XXX {
  field $x :param(p);
  field $y :param(p);
}
EXPECT
Cannot assign :param(p) to field $y because that name is already in use at - line 6.
########
use strict;
no warnings 'experimental::class';
use feature 'class';
class XXX {
  field $x :param(p);
}
class YYY :isa(XXX) {
  field $y :param(p);
}
EXPECT
Cannot assign :param(p) to field $y because that name is already in use at - line 8.