]> Cypherpunks repositories - gostls13.git/commitdiff
more helpful messages for name-related syntax errors.
authorRuss Cox <rsc@golang.org>
Thu, 18 Sep 2008 20:32:14 +0000 (13:32 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 18 Sep 2008 20:32:14 +0000 (13:32 -0700)
R=ken
OCL=15477
CL=15479

src/cmd/gc/go.y
src/cmd/gc/walk.c

index dedef05d52402e8a61b7592a6b6189481d214010..071d51b648e3f98cb2f767006011077fdd04e25f 100644 (file)
@@ -1644,3 +1644,58 @@ hidden_importfield:
                $$ = $2;
                $$->fsym = $1;
        }
+
+/*
+ * helpful error messages.
+ * THIS SECTION MUST BE AT THE END OF THE FILE.
+ *
+ * these rules trigger reduce/reduce conflicts in the grammar.
+ * they are safe because reduce/reduce conflicts are resolved
+ * in favor of rules appearing earlier in the grammar, and these
+ * are at the end of the file.
+ *
+ * to check whether the rest of the grammar is free of
+ * reduce/reduce conflicts, comment this section out by
+ * removing the slash on the next line.
+ */
+lpack:
+       LATYPE
+       {
+               yyerror("%s is type, not package", $1->name);
+               YYERROR;
+       }
+
+laconst:
+       LPACK
+       {
+               // for LALR(1) reasons, using laconst works here
+               // but lname does not.  even so, the messages make
+               // more sense saying "var" instead of "const".
+               yyerror("%s is package, not var", $1->name);
+               YYERROR;
+       }
+|      LATYPE
+       {
+               yyerror("%s is type, not var", $1->name);
+               YYERROR;
+       }
+
+latype:
+       LACONST
+       {
+               yyerror("%s is const, not type", $1->name);
+               YYERROR;
+       }
+|      LPACK
+       {
+               yyerror("%s is package, not type", $1->name);
+               YYERROR;
+       }
+|      LNAME
+       {
+               yyerror("%s is var, not type", $1->name);
+               YYERROR;
+       }
+
+/**/
+
index 7349915b2f9e1154f2edd9f044a3ebb2ec2cbd3f..ecdb4dd7f7b0f3b962764609de7a6eff82beeb69 100644 (file)
@@ -1420,7 +1420,7 @@ walkdot(Node *n)
 
        f = lookdot(n->right, t->method);
        if(f == T) {
-               yyerror("undefined DOT reference %N", n->right);
+               yyerror("undefined DOT %s", n->right->sym->name);
                return;
        }