]> Cypherpunks repositories - gostls13.git/commitdiff
bug181 - type T *struct { T } is an invalid embedded type
authorRuss Cox <rsc@golang.org>
Fri, 7 Aug 2009 20:14:01 +0000 (13:14 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 7 Aug 2009 20:14:01 +0000 (13:14 -0700)
R=ken
OCL=32886
CL=32886

src/cmd/gc/dcl.c
src/cmd/gc/go.h
src/cmd/gc/walk.c
test/fixedbugs/bug181.go [new file with mode: 0644]

index 1768f2e121ffc38d87d51a29dfc38d2b55a92b9e..fe64ee08d7a8daa4ef6086b2422075666d7fee98 100644 (file)
@@ -900,8 +900,10 @@ stotype(NodeList *l, int et, Type **t)
                                t1 = n->type;
                                if(t1->sym == S && isptr[t1->etype])
                                        t1 = t1->type;
-                               if(t1 != T && isptr[t1->etype])
+                               if(isptr[t1->etype])
                                        yyerror("embedded type cannot be a pointer");
+                               else if(t1->etype == TFORW && t1->embedlineno == 0)
+                                       t1->embedlineno = lineno;
                        }
                }
 
index 3c11d038a0b7bf20d4728265525ec06a21329a48..3ddeca1dffc36597da02b64687f3f98a15ccf62c 100644 (file)
@@ -175,6 +175,7 @@ struct      Type
        int32   bound;          // negative is dynamic array
 
        int32   maplineno;      // first use of TFORW as map key
+       int32   embedlineno;    // first use of TFORW as embedded type
 };
 #define        T       ((Type*)0)
 
index 044a29643b945c613b598451153230f706c8128b..2298c659cba67ea3b1a3b6dcac184eadf223072d 100644 (file)
@@ -111,7 +111,7 @@ walkdeflist(NodeList *l)
 void
 walkdef(Node *n)
 {
-       int lno, maplineno;
+       int lno, maplineno, embedlineno;
        NodeList *init;
        Node *e;
        Type *t;
@@ -210,6 +210,7 @@ walkdef(Node *n)
                // copy new type and clear fields
                // that don't come along
                maplineno = n->type->maplineno;
+               embedlineno = n->type->embedlineno;
                *n->type = *t;
                t = n->type;
                t->sym = n->sym;
@@ -226,6 +227,11 @@ walkdef(Node *n)
                        lineno = maplineno;
                        maptype(n->type, types[TBOOL]);
                }
+               if(embedlineno) {
+                       lineno = embedlineno;
+                       if(isptr[t->etype])
+                               yyerror("embedded type cannot be a pointer");
+               }
                break;
        }
 
diff --git a/test/fixedbugs/bug181.go b/test/fixedbugs/bug181.go
new file mode 100644 (file)
index 0000000..f87bc9d
--- /dev/null
@@ -0,0 +1,11 @@
+// errchk $G $D/$F.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.
+
+package main
+
+type T *struct {
+       T;      // ERROR "embed.*pointer"
+}