]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix shift/reduce conflict in go.y export syntax
authorRuss Cox <rsc@golang.org>
Mon, 24 May 2010 23:55:23 +0000 (16:55 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 24 May 2010 23:55:23 +0000 (16:55 -0700)
Fixes #771.

R=ken2
CC=golang-dev
https://golang.org/cl/1267042

src/cmd/gc/go.y
src/cmd/gc/subr.c
test/fixedbugs/bug282.dir/p1.go [new file with mode: 0644]
test/fixedbugs/bug282.dir/p2.go [new file with mode: 0644]
test/fixedbugs/bug282.go [new file with mode: 0644]

index 8128e8608e29a7da216fa0f9bb517d160db75e28..5aac463c8cfd6382dfbb7dcd589a0667990d873d 100644 (file)
@@ -74,6 +74,8 @@
 %type  <node>  indcl interfacetype structtype ptrtype
 %type  <node>  recvchantype non_recvchantype othertype fnret_type fntype
 
+%type  <val>   hidden_tag
+
 %type  <sym>   hidden_importsym hidden_pkg_importsym
 
 %type  <node>  hidden_constant hidden_literal hidden_dcl
@@ -1709,12 +1711,12 @@ hidden_dcl:
        }
 
 hidden_structdcl:
-       sym hidden_type oliteral
+       sym hidden_type hidden_tag
        {
                $$ = nod(ODCLFIELD, newname($1), typenod($2));
                $$->val = $3;
        }
-|      '?' hidden_type oliteral
+|      '?' hidden_type hidden_tag
        {
                Sym *s;
 
@@ -1728,6 +1730,15 @@ hidden_structdcl:
                $$->val = $3;
        }
 
+hidden_tag:
+       {
+               $$.ctype = CTxxx;
+       }
+|      ':' LLITERAL    // extra colon avoids conflict with "" looking like beginning of "".typename
+       {
+               $$ = $2;
+       }
+
 hidden_interfacedcl:
        sym '(' ohidden_funarg_list ')' ohidden_funres
        {
index b0192adf331c7fa48fa9e6ab8a0120975395a3ff..cf7b1865cfb236b7081b7236265dbba1ac7fcf14 100644 (file)
@@ -1295,8 +1295,12 @@ Tpretty(Fmt *fp, Type *t)
                                fmtprint(fp, "... %T", t->type->type);
                } else
                        fmtprint(fp, "%T", t->type);
-               if(t->note)
-                       fmtprint(fp, " \"%Z\"", t->note);
+               if(t->note) {   
+                       fmtprint(fp, " ");
+                       if(exporting)
+                               fmtprint(fp, ":");
+                       fmtprint(fp, "\"%Z\"", t->note);
+               }
                return 0;
 
        case TFORW:
diff --git a/test/fixedbugs/bug282.dir/p1.go b/test/fixedbugs/bug282.dir/p1.go
new file mode 100644 (file)
index 0000000..b562755
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p1
+
+type T struct {
+       f func() "x"
+}
+
diff --git a/test/fixedbugs/bug282.dir/p2.go b/test/fixedbugs/bug282.dir/p2.go
new file mode 100644 (file)
index 0000000..3f8bd9d
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p2
+
+import _ "./p1"
+
diff --git a/test/fixedbugs/bug282.go b/test/fixedbugs/bug282.go
new file mode 100644 (file)
index 0000000..463f21e
--- /dev/null
@@ -0,0 +1,7 @@
+// $G $D/$F.dir/p1.go && $G $D/$F.dir/p2.go
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+ignored