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