]> Cypherpunks repositories - gostls13.git/commitdiff
bug134
authorRuss Cox <rsc@golang.org>
Tue, 27 Jan 2009 01:06:20 +0000 (17:06 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 27 Jan 2009 01:06:20 +0000 (17:06 -0800)
R=ken
OCL=23532
CL=23532

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

index a60637c258c7343b8ad3aea1922b66e8d5a1d62e..edac4ca2c0cb697968ba64b5068033cc29ca56a4 100644 (file)
@@ -313,9 +313,9 @@ addmethod(Node *n, Type *t, int local)
        }
 
        if(d == T)
-               stotype(n, &pa->method);
+               stotype(n, 0, &pa->method);
        else
-               stotype(n, &d->down);
+               stotype(n, 0, &d->down);
 
        if(dflag())
                print("method         %S of type %T\n", sf, pa);
@@ -472,36 +472,43 @@ funcbody(Node *n)
  * turn a parsed struct into a type
  */
 Type**
-stotype(Node *n, Type **t)
+stotype(Node *n, int et, Type **t)
 {
        Type *f;
        Iter save;
        String *note;
+       int lno;
 
+       lno = lineno;
        n = listfirst(&save, &n);
 
 loop:
        note = nil;
        if(n == N) {
                *t = T;
+               lineno = lno;
                return t;
        }
 
+       lineno = n->lineno;
        if(n->op == OLIST) {
                // recursive because it can be lists of lists
-               t = stotype(n, t);
+               t = stotype(n, et, t);
                goto next;
        }
 
        if(n->op != ODCLFIELD || n->type == T)
                fatal("stotype: oops %N\n", n);
 
+       if(et == TSTRUCT && n->type->etype == TFUNC)
+               yyerror("bad structure field type: %T", n->type);
+
        switch(n->val.ctype) {
        case CTSTR:
                note = n->val.u.sval;
                break;
        default:
-               yyerror("structure field annotation must be string");
+               yyerror("field annotation must be string");
        case CTxxx:
                note = nil;
                break;
@@ -546,7 +553,7 @@ dostruct(Node *n, int et)
        }
        t = typ(et);
        t->funarg = funarg;
-       stotype(n, &t->type);
+       stotype(n, et, &t->type);
        if(!funarg)
                checkwidth(t);
        return t;
index e1f64b5424c1398d6153d63eb5708c27f33b51e2..461c00b217b7d284987eb86535b4d40aa883746d 100644 (file)
@@ -707,7 +707,7 @@ void        funchdr(Node*);
 void   funcargs(Type*);
 void   funcbody(Node*);
 Type*  dostruct(Node*, int);
-Type** stotype(Node*, Type**);
+Type** stotype(Node*, int, Type**);
 Type*  sortinter(Type*);
 void   markdcl(void);
 void   popdcl(void);
diff --git a/test/fixedbugs/bug134.go b/test/fixedbugs/bug134.go
new file mode 100644 (file)
index 0000000..e0817a4
--- /dev/null
@@ -0,0 +1,11 @@
+// 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.
+
+// errchk $G $D/$F.go
+
+package main
+
+type T struct {
+       v ();  // ERROR "field type"
+}