]> Cypherpunks.ru repositories - gostls13.git/commitdiff
gc: ... T corner cases
authorRuss Cox <rsc@golang.org>
Mon, 1 Feb 2010 18:49:24 +0000 (10:49 -0800)
committerRuss Cox <rsc@golang.org>
Mon, 1 Feb 2010 18:49:24 +0000 (10:49 -0800)
more to come, but should suffice for Printf work.

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

src/cmd/gc/closure.c
src/cmd/gc/dcl.c
src/cmd/gc/reflect.c
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
test/ddd.go
test/ddd1.go

index 33c576c878e2165774c211132de2b9f66dedc4f5..c194a0df324968841b8f24cc622ec9d19a84caa5 100644 (file)
@@ -11,7 +11,7 @@
 void
 closurehdr(Node *ntype)
 {
-       Node *n, *name;
+       Node *n, *name, *a;
        NodeList *l;
 
        n = nod(OCLOSURE, N, N);
@@ -33,7 +33,11 @@ closurehdr(Node *ntype)
                name = l->n->left;
                if(name)
                        name = newname(name->sym);
-               ntype->list = list(ntype->list, nod(ODCLFIELD, name, l->n->right));
+               a = nod(ODCLFIELD, name, l->n->right);
+               a->isddd = l->n->isddd;
+               if(name)
+                       name->isddd = a->isddd;
+               ntype->list = list(ntype->list, a);
        }
        for(l=n->rlist; l; l=l->next) {
                name = l->n->left;
index aeb3e3916aae0e7fd5c53b248248602553dab128..b0b06f7d3223dc860cde34973c369aaa6b9eaad7 100644 (file)
@@ -501,6 +501,7 @@ oldname(Sym *s)
                        c = nod(ONAME, N, N);
                        c->sym = s;
                        c->class = PPARAMREF;
+                       c->isddd = n->isddd;
                        c->defn = n;
                        c->addable = 0;
                        c->ullman = 2;
index 3f90f68e93e43d088195ac1bb909ca90cf688dfd..12d27aa88636239d6598cc5908c877c0d7385e3f 100644 (file)
@@ -115,6 +115,7 @@ methodfunc(Type *f, int use_receiver)
        for(t=getinargx(f)->type; t; t=t->down) {
                d = nod(ODCLFIELD, N, N);
                d->type = t->type;
+               d->isddd = t->isddd;
                in = list(in, d);
        }
 
index a9384247040642e093e9ae46a9b4747fba9eb08b..40d8b6f9dbac8401d02930a087a27cf36fefd2f4 100644 (file)
@@ -1004,6 +1004,9 @@ Jconv(Fmt *fp)
        if(n->dodata != 0)
                fmtprint(fp, " dd(%d)", n->dodata);
 
+       if(n->isddd != 0)
+               fmtprint(fp, " isddd(%d)", n->isddd);
+
        return 0;
 }
 
@@ -2585,6 +2588,9 @@ adddot(Node *n)
        t = n->left->type;
        if(t == T)
                goto ret;
+       
+       if(n->left->op == OTYPE)
+               goto ret;
 
        if(n->right->op != ONAME)
                goto ret;
@@ -2783,6 +2789,9 @@ structargs(Type **tl, int mustname)
                        n = newname(lookup(buf));
                }
                a = nod(ODCLFIELD, n, typenod(t->type));
+               a->isddd = t->isddd;
+               if(n != N)
+                       n->isddd = t->isddd;
                args = list(args, a);
        }
        return args;
index dfd67b71cb1f39538a30728c7a7099ad7f9d449e..4204ee4568f969188647b1f3066c1a38aa2a17bd 100644 (file)
@@ -470,7 +470,7 @@ reswitch:
                }
                if(l->op == OTYPE) {
                        if(n->type->etype != TFUNC || n->type->thistuple != 1) {
-                               yyerror("type %T has no method %s", n->left->type, sym);
+                               yyerror("type %T has no method %hS", n->left->type, sym);
                                n->type = T;
                                goto error;
                        }
@@ -1527,7 +1527,7 @@ typecheckaste(int op, Type *tstruct, NodeList *nl, char *desc)
                                // TODO(rsc): drop first if in DDD cleanup
                                if(t->etype != TINTER)
                                if(checkconv(nl->n->type, t->type, 0, &xx, &yy, desc) < 0)
-                                       yyerror("cannot use %#N as type %T in %s", nl->n, t->type, desc);                                       
+                                       yyerror("cannot use %+N as type %T in %s", nl->n, t->type, desc);                                       
                        }
                        goto out;
                }
index 682f22ffe300957e0fff5ecdd93cb47bdaf86699..08c88f4ff256bdd0307d8faec4ab3f7be1f544dd 100644 (file)
@@ -14,6 +14,18 @@ func sum(args ...int) int {
        return s
 }
 
+func sumC(args ...int) int {
+       return func() int { return sum(args) } ()
+}
+
+/* TODO(rsc)
+var sumD = func(args ...int) int { return sum(args) }
+
+var sumE = func() func(...int) int { return func(args ...int) int { return sum(args) } } ()
+
+var sumF = func(args ...int) func() int { return func() int { return sum(args) } }
+*/
+
 func sumA(args []int) int {
        s := 0
        for _, v := range args {
@@ -40,6 +52,14 @@ func ln(args ...T) int { return len(args) }
 
 func ln2(args ...T) int { return 2 * ln(args) }
 
+func (*T) Sum(args ...int) int {
+       return sum(args)
+}
+
+type U struct {
+       *T
+}
+
 func main() {
        if x := sum(1, 2, 3); x != 6 {
                panicln("sum 6", x)
@@ -53,6 +73,20 @@ func main() {
        if x := sum(1, 8); x != 9 {
                panicln("sum 9", x)
        }
+       if x := sumC(4, 5, 6); x != 15 {
+               panicln("sumC 15", x)
+       }
+/* TODO(rsc)
+       if x := sumD(4, 5, 7); x != 16 {
+               panicln("sumD 16", x)
+       }
+       if x := sumE(4, 5, 8); x != 17 {
+               panicln("sumE 17", x)
+       }
+       if x := sumF(4, 5, 9)(); x != 18 {
+               panicln("sumF 18", x)
+       }
+*/
        if x := sum2(1, 2, 3); x != 2*6 {
                panicln("sum 6", x)
        }
@@ -102,4 +136,36 @@ func main() {
        if x := ln2([]T{}); x != 2*1 {
                panicln("ln2 1", x)
        }
+       if x := ((*T)(nil)).Sum(1,3,5,7); x != 16 {
+               panicln("(*T)(nil).Sum", x)
+       }
+       if x := (*T).Sum(nil, 1, 3, 5, 6); x != 15 {
+               panicln("(*T).Sum", x)
+       }
+       if x := (&U{}).Sum(1,3,5,5); x != 14 {
+               panicln("(&U{}).Sum", x)
+       }
+       var u U
+       if x := u.Sum(1,3,5,4); x != 13 {
+               panicln("u.Sum", x)
+       }
+       if x := (&u).Sum(1,3,5,3); x != 12 {
+               panicln("(&u).Sum", x)
+       }
+       var i interface { Sum(...int) int } = &u
+       if x := i.Sum(2,3,5,7); x != 17 {
+               panicln("i(=&u).Sum", x)
+       }
+       i = u
+       if x := i.Sum(2,3,5,6); x != 16 {
+               panicln("i(=u).Sum", x)
+       }
+/* TODO(rsc): Enable once nested method expressions work.
+       if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 {
+               panicln("(*U).Sum", x)
+       }
+       if x := U.Sum(U{}, 1, 3, 5, 1); x != 10 {
+               panicln("U.Sum", x)
+       }
+*/
 }
index da03a70c9d0da591640688c12e040ea5172cd8c0..4f830c582f1e817ab3480ff38922b426b418fbd0 100644 (file)
@@ -14,7 +14,7 @@ var (
        _ = sum(1.0, 2.0)
        _ = sum(1.5)      // ERROR "integer"
        _ = sum("hello")  // ERROR "convert"
-       _ = sum([]int{1}) // ERROR "slice literal as type int"
+       _ = sum([]int{1}) // ERROR "slice literal.*as type int"
 )
 
 type T []T