produce better error message when \N{...} is used without
authorGurusamy Sarathy <gsar@cpan.org>
Sun, 19 Mar 2000 07:09:32 +0000 (07:09 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Sun, 19 Mar 2000 07:09:32 +0000 (07:09 +0000)
"use charnames ..."

p4raw-id: //depot/perl@5819

pod/perldelta.pod
pod/perldiag.pod
toke.c

index 0481f9a..e7eab2b 100644 (file)
@@ -2205,15 +2205,12 @@ message indicates the type of reference that was expected. This usually
 indicates a syntax error in dereferencing the constant value.
 See L<perlsub/"Constant Functions"> and L<constant>.
 
-=item constant(%s): %%^H is not localized
-
-(F) When setting compile-time-lexicalized hash %^H one should set the 
-corresponding bit of $^H as well.
-
 =item constant(%s): %s
 
-(F) Compile-time-substitutions (such as overloaded constants and
-character names) were not correctly set up.
+(F) The parser found inconsistencies either while attempting to define an
+overloaded constant, or when trying to find the character name specified
+in the C<\N{...}> escape.  Perhaps you forgot to load the corresponding
+C<overload> or C<charnames> pragma?  See L<charnames> and L<overload>.
 
 =item CORE::%s is not a keyword
 
index 6f96ec2..93b967b 100644 (file)
@@ -1255,15 +1255,12 @@ workarounds.
 inlining.  See L<perlsub/"Constant Functions"> for commentary and
 workarounds.
 
-=item constant(%s): %%^H is not localized
-
-(F) When setting compile-time-lexicalized hash %^H one should set the 
-corresponding bit of $^H as well.
-
 =item constant(%s): %s
 
-(F) Compile-time-substitutions (such as overloaded constants and
-character names) were not correctly set up.
+(F) The parser found inconsistencies either while attempting to define an
+overloaded constant, or when trying to find the character name specified
+in the C<\N{...}> escape.  Perhaps you forgot to load the corresponding
+C<overload> or C<charnames> pragma?  See L<charnames> and L<overload>.
 
 =item Copy method did not return a reference
 
diff --git a/toke.c b/toke.c
index 3745071..0ec3cf6 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -5648,30 +5648,28 @@ S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
     SV *res;
     SV **cvp;
     SV *cv, *typesv;
-    const char *why, *why1, *why2;
+    const char *why1, *why2, *why3;
     
-    if (!(PL_hints & HINT_LOCALIZE_HH)) {
+    if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
        SV *msg;
        
-       why = "%^H is not localized";
-    report_short:
-       why1 = why2 = "";
+       why1 = "%^H is not consistent";
+       why2 = strEQ(key,"charnames")
+              ? " (missing \"use charnames ...\"?)"
+              : "";
+       why3 = "";
     report:
        msg = Perl_newSVpvf(aTHX_ "constant(%s): %s%s%s", 
-                           (type ? type: "undef"), why1, why2, why);
+                           (type ? type: "undef"), why1, why2, why3);
        yyerror(SvPVX(msg));
        SvREFCNT_dec(msg);
        return sv;
     }
-    if (!table) {
-       why = "%^H is not defined";
-       goto report_short;
-    }
     cvp = hv_fetch(table, key, strlen(key), FALSE);
     if (!cvp || !SvOK(*cvp)) {
-       why = "} is not defined";
        why1 = "$^H{";
        why2 = key;
+       why3 = "} is not defined";
        goto report;
     }
     sv_2mortal(sv);                    /* Parent created it permanently */
@@ -5719,9 +5717,9 @@ S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
     POPSTACK;
     
     if (!SvOK(res)) {
-       why = "}} did not return a defined value";
        why1 = "Call to &{$^H{";
        why2 = key;
+       why3 = "}} did not return a defined value";
        sv = res;
        goto report;
     }