From: Jarkko Hietaniemi Date: Wed, 20 Jun 2001 18:58:06 +0000 (+0000) Subject: Fix for ID 20010619.002 "When building hash, hash keys that X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce29ac451034df067115e81c1d12f5f8c0114302;p=p5sagit%2Fp5-mst-13.2.git Fix for ID 20010619.002 "When building hash, hash keys that are function calls are not being called", from Abhijit. p4raw-id: //depot/perl@10763 --- diff --git a/t/base/lex.t b/t/base/lex.t index c7fb0e4..4df4954 100755 --- a/t/base/lex.t +++ b/t/base/lex.t @@ -1,6 +1,6 @@ #!./perl -print "1..51\n"; +print "1..54\n"; $x = 'x'; @@ -245,3 +245,18 @@ EOT print "ok $test\n"; ++$test; } + +# Tests 52-54 +# => should only quote foo::bar if it isn't a real sub. AMS, 20010621 + +sub xyz::foo { "bar" } +my %str = ( + foo => 1, + xyz::foo => 1, + xyz::bar => 1, +); + +my $test = 52; +print ((exists $str{foo} ? "" : "not ")."ok $test\n"); ++$test; +print ((exists $str{bar} ? "" : "not ")."ok $test\n"); ++$test; +print ((exists $str{xyz::bar} ? "" : "not ")."ok $test\n"); ++$test; diff --git a/toke.c b/toke.c index 34e2fd4..faa8bba 100644 --- a/toke.c +++ b/toke.c @@ -3925,6 +3925,7 @@ Perl_yylex(pTHX) default: /* not a keyword */ just_a_word: { SV *sv; + int pkgname = 0; char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); /* Get the rest if it looks like a package qualifier */ @@ -3937,6 +3938,7 @@ Perl_yylex(pTHX) Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, *s == '\'' ? "'" : "::"); len += morelen; + pkgname = 1; } if (PL_expect == XOPERATOR) { @@ -4024,12 +4026,11 @@ Perl_yylex(pTHX) } } - PL_expect = XOPERATOR; s = skipspace(s); /* Is this a word before a => operator? */ - if (*s == '=' && s[1] == '>') { + if (*s == '=' && s[1] == '>' && !pkgname) { CLINE; sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))