Commit | Line | Data |
d19d8ad3 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More tests => 3; |
5 | |
6 | my $Has_PH = $] < 5.009; |
7 | my $Field = $Has_PH ? "pseudo-hash field" : "class field"; |
8 | |
9 | { |
10 | package Parent; |
11 | use fields qw(this that); |
12 | sub new { fields::new(shift) } |
13 | } |
14 | |
15 | { |
16 | package Child; |
17 | use base qw(Parent); |
18 | } |
19 | |
20 | my Child $obj = Child->new; |
21 | |
22 | eval q(return; my Child $obj3 = $obj; $obj3->{notthere} = ""); |
23 | like $@, |
24 | qr/^No such .*field "notthere" in variable \$obj3 of type Child/, |
25 | "Compile failure of undeclared fields (helem)"; |
26 | |
27 | # Slices |
28 | # We should get compile time failures field name typos |
29 | SKIP: { |
30 | skip("Pseudo-hashes do not support compile-time slice checks", 2) |
31 | if $Has_PH; |
32 | |
33 | eval q(return; my Child $obj3 = $obj; my $k; @$obj3{$k,'notthere'} = ()); |
34 | like $@, |
35 | qr/^No such .*field "notthere" in variable \$obj3 of type Child/, |
36 | "Compile failure of undeclared fields (hslice)"; |
37 | |
38 | eval q(return; my Child $obj3 = $obj; my $k; @{$obj3}{$k,'notthere'} = ()); |
39 | like |
40 | $@, qr/^No such .*field "notthere" in variable \$obj3 of type Child/, |
41 | "Compile failure of undeclared fields (hslice (block form))"; |
42 | } |