From: Rafael Garcia-Suarez Date: Fri, 19 Nov 2004 14:48:35 +0000 (+0000) Subject: Make "err" a weak keyword; X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7fc307b5b2c2555eb36e722b92df29f8a8d5db19;p=p5sagit%2Fp5-mst-13.2.git Make "err" a weak keyword; that is, it will be overriden by any sub named "err", except when really an operator is expected at this point. ([perl #32347]) p4raw-id: //depot/perl@23519 --- diff --git a/t/op/dor.t b/t/op/dor.t index 8740a5c..079631a 100644 --- a/t/op/dor.t +++ b/t/op/dor.t @@ -10,7 +10,7 @@ BEGIN { package main; require './test.pl'; -plan( tests => 35 ); +plan( tests => 41 ); my($x); @@ -82,3 +82,15 @@ like( $@, qr/^Search pattern not terminated/ ); is(0 // 2, 0, ' // : left-hand operand not optimized away'); is('' // 2, '', ' // : left-hand operand not optimized away'); is(undef // 2, 2, ' // : left-hand operand optimized away'); + +# [perl #32347] err should be a weak keyword + +package weakerr; + +sub err { "<@_>" } +::is( (shift() err 42), 42, 'err as an operator' ); +::is( (shift err 42), 42, 'err as an operator, with ambiguity' ); +::is( (err 2), "<2>", 'err as a function without parens' ); +::is( err(2, 3), "<2 3>", 'err as a function with parens' ); +::is( err(), "<>", 'err as a function without arguments' ); +::is( err, "<>", 'err as a function without parens' ); diff --git a/toke.c b/toke.c index 7c9d88f..a7a9068 100644 --- a/toke.c +++ b/toke.c @@ -4037,6 +4037,16 @@ Perl_yylex(pTHX) { tmp = 0; /* any sub overrides "weak" keyword */ } + else if (gv && !gvp + && tmp == -KEY_err + && GvCVu(gv) + && PL_expect != XOPERATOR + && PL_expect != XTERMORDORDOR) + { + /* any sub overrides the "err" keyword, except when really an + * operator is expected */ + tmp = 0; + } else { /* no override */ tmp = -tmp; if (tmp == KEY_dump && ckWARN(WARN_MISC)) {