xref: /openbsd-src/gnu/usr.bin/perl/t/lib/croak/class (revision 513cf72f82c16dd38f89b0e7a0ec4a163d87f81f)
1__END__
2# Method calls on no args
3no warnings 'experimental::class';
4use feature 'class';
5class XXX { method m { } }
6XXX::m()
7EXPECT
8Cannot invoke method "m" on a non-instance at - line 5.
9########
10# Method calls on non-ref
11no warnings 'experimental::class';
12use feature 'class';
13class XXX { method m { } }
14XXX::m(123)
15EXPECT
16Cannot invoke method "m" on a non-instance at - line 5.
17########
18# Method calls on non-object
19no warnings 'experimental::class';
20use feature 'class';
21class XXX { method m { } }
22XXX::m([])
23EXPECT
24Cannot invoke method "m" on a non-instance at - line 5.
25########
26# Method calls from a different class
27no warnings 'experimental::class';
28use feature 'class';
29class XXX { method m { } }
30class YYY {}
31YYY->new->XXX::m();
32EXPECT
33Cannot invoke a method of "XXX" on an instance of "YYY" at - line 6.
34########
35no warnings 'experimental::class';
36use feature 'class';
37class XXX {}
38bless [], "XXX";
39EXPECT
40Attempt to bless into a class at - line 4.
41########
42no warnings 'experimental::class';
43use feature 'class';
44class XXX {}
45bless(XXX->new, "main");
46EXPECT
47Can't bless an object reference at - line 4.
48########
49no warnings 'experimental::class';
50use feature 'class';
51class XXX { field $zz; $zz = 123; }
52EXPECT
53Field $zz is not accessible outside a method at - line 3.
54########
55no warnings 'experimental::class';
56use feature 'class';
57class XXX { field $x; sub f { print $x } }
58EXPECT
59Field $x is not accessible outside a method at - line 3.
60########
61no warnings 'experimental::class';
62use feature 'class';
63class XXX {
64  field $x;
65  class YYY { method m { print $x } }
66}
67EXPECT
68Field $x of "XXX" is not accessible in a method of "YYY" at - line 5.
69########
70no warnings 'experimental::class';
71use feature 'class';
72class XXX {}
73class XXX {}
74EXPECT
75Cannot reopen existing class "XXX" at - line 4.
76########
77no warnings 'experimental::class';
78use feature 'class';
79class XXX {}
80push @XXX::ISA, q(Another);
81EXPECT
82Modification of a read-only value attempted at - line 4.
83########
84no warnings 'experimental::class';
85use feature 'class';
86BEGIN { push @XXX::ISA, q(Another); }
87class XXX {}
88EXPECT
89Cannot create class XXX as it already has a non-empty @ISA at - line 4.
90########
91use strict;
92no warnings 'experimental::class';
93use feature 'class';
94class XXX {
95  field $x = $self + 1;
96}
97EXPECT
98Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at - line 5.
99Execution of - aborted due to compilation errors.
100########
101# This test is known to leak: see GH #20812. Skip it for now so that ASAN
102# smokes don't fail. Start failing again on the next development branch so
103# that the issue isn't forgotten
104# SKIP ? $] < 5.039
105use strict;
106no warnings 'experimental::class';
107use feature 'class';
108class XXX {
109  field $x = last;
110}
111EXPECT
112Can't "last" out of field initialiser expression at - line 5.
113########
114use strict;
115no warnings 'experimental::class';
116use feature 'class';
117class XXX {
118  field $x :param(p);
119  field $y :param(p);
120}
121EXPECT
122Cannot assign :param(p) to field $y because that name is already in use at - line 6.
123########
124use strict;
125no warnings 'experimental::class';
126use feature 'class';
127class XXX {
128  field $x :param(p);
129}
130class YYY :isa(XXX) {
131  field $y :param(p);
132}
133EXPECT
134Cannot assign :param(p) to field $y because that name is already in use at - line 8.
135