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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
__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.
########
# This test is known to leak: see GH #20812.
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.
########
use strict;
no warnings 'experimental::class';
use feature 'class';
class XXX {
my $classname = __CLASS__;
}
EXPECT
Cannot use __CLASS__ outside of a method or field initializer expression at - line 5.
########
# NAME try to create an object of incomplete class (error)
use v5.36;
use feature 'class';
no warnings 'experimental::class';
eval "class C {";
C->new;
EXPECT
Can't locate object method "new" via package "C" at - line 5.
########
# NAME try to create an object of incomplete class (compile-time)
use v5.36;
use feature 'class';
no warnings 'experimental::class';
class C { BEGIN { C->new; } };
EXPECT
Cannot create an object of incomplete class "C" at - line 4.
BEGIN failed--compilation aborted at - line 4.
########
# Invalid method name for :reader attribute
use v5.36;
use feature 'class';
no warnings 'experimental::class';
class XXX {
field $x :reader(abc-def);
}
EXPECT
"abc-def" is not a valid name for a generated method at - line 6.
########
# Invalid method name for :writer attribute
use v5.36;
use feature 'class';
no warnings 'experimental::class';
class XXX {
field $x :writer(set-abc-def);
}
EXPECT
"set-abc-def" is not a valid name for a generated method at - line 6.
########
# Writer on non-scalar field
use v5.36;
use feature 'class';
no warnings 'experimental::class';
class XXX {
field @things :writer;
}
EXPECT
Cannot apply a :writer attribute to a non-scalar field at - line 6.
########
use v5.36;
use feature 'class';
no warnings 'experimental::class';
sub f { last }
class X {
field $x = ::f();
}
# two warnings since we exit the initfields cv and f()
X->new for 0;
EXPECT
Exiting subroutine via last at - line 4.
Exiting subroutine via last at - line 4.
Can't "last" outside a loop block at - line 4.
########
use v5.36;
use feature 'class';
no warnings 'experimental::class';
class X {
field $x;
ADJUST {
last;
}
}
X->new for 0;
EXPECT
Exiting subroutine via last at - line 7.
Can't "last" outside a loop block at - line 7.
|