mirror of
https://github.com/golang/go
synced 2024-11-22 09:24:41 -07:00
gc: ... T corner cases
more to come, but should suffice for Printf work. R=ken2 CC=golang-dev https://golang.org/cl/197044
This commit is contained in:
parent
cecd163625
commit
bea730d1f9
@ -11,7 +11,7 @@
|
|||||||
void
|
void
|
||||||
closurehdr(Node *ntype)
|
closurehdr(Node *ntype)
|
||||||
{
|
{
|
||||||
Node *n, *name;
|
Node *n, *name, *a;
|
||||||
NodeList *l;
|
NodeList *l;
|
||||||
|
|
||||||
n = nod(OCLOSURE, N, N);
|
n = nod(OCLOSURE, N, N);
|
||||||
@ -33,7 +33,11 @@ closurehdr(Node *ntype)
|
|||||||
name = l->n->left;
|
name = l->n->left;
|
||||||
if(name)
|
if(name)
|
||||||
name = newname(name->sym);
|
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) {
|
for(l=n->rlist; l; l=l->next) {
|
||||||
name = l->n->left;
|
name = l->n->left;
|
||||||
|
@ -501,6 +501,7 @@ oldname(Sym *s)
|
|||||||
c = nod(ONAME, N, N);
|
c = nod(ONAME, N, N);
|
||||||
c->sym = s;
|
c->sym = s;
|
||||||
c->class = PPARAMREF;
|
c->class = PPARAMREF;
|
||||||
|
c->isddd = n->isddd;
|
||||||
c->defn = n;
|
c->defn = n;
|
||||||
c->addable = 0;
|
c->addable = 0;
|
||||||
c->ullman = 2;
|
c->ullman = 2;
|
||||||
|
@ -115,6 +115,7 @@ methodfunc(Type *f, int use_receiver)
|
|||||||
for(t=getinargx(f)->type; t; t=t->down) {
|
for(t=getinargx(f)->type; t; t=t->down) {
|
||||||
d = nod(ODCLFIELD, N, N);
|
d = nod(ODCLFIELD, N, N);
|
||||||
d->type = t->type;
|
d->type = t->type;
|
||||||
|
d->isddd = t->isddd;
|
||||||
in = list(in, d);
|
in = list(in, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1004,6 +1004,9 @@ Jconv(Fmt *fp)
|
|||||||
if(n->dodata != 0)
|
if(n->dodata != 0)
|
||||||
fmtprint(fp, " dd(%d)", n->dodata);
|
fmtprint(fp, " dd(%d)", n->dodata);
|
||||||
|
|
||||||
|
if(n->isddd != 0)
|
||||||
|
fmtprint(fp, " isddd(%d)", n->isddd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2586,6 +2589,9 @@ adddot(Node *n)
|
|||||||
if(t == T)
|
if(t == T)
|
||||||
goto ret;
|
goto ret;
|
||||||
|
|
||||||
|
if(n->left->op == OTYPE)
|
||||||
|
goto ret;
|
||||||
|
|
||||||
if(n->right->op != ONAME)
|
if(n->right->op != ONAME)
|
||||||
goto ret;
|
goto ret;
|
||||||
s = n->right->sym;
|
s = n->right->sym;
|
||||||
@ -2783,6 +2789,9 @@ structargs(Type **tl, int mustname)
|
|||||||
n = newname(lookup(buf));
|
n = newname(lookup(buf));
|
||||||
}
|
}
|
||||||
a = nod(ODCLFIELD, n, typenod(t->type));
|
a = nod(ODCLFIELD, n, typenod(t->type));
|
||||||
|
a->isddd = t->isddd;
|
||||||
|
if(n != N)
|
||||||
|
n->isddd = t->isddd;
|
||||||
args = list(args, a);
|
args = list(args, a);
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
|
@ -470,7 +470,7 @@ reswitch:
|
|||||||
}
|
}
|
||||||
if(l->op == OTYPE) {
|
if(l->op == OTYPE) {
|
||||||
if(n->type->etype != TFUNC || n->type->thistuple != 1) {
|
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;
|
n->type = T;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -1527,7 +1527,7 @@ typecheckaste(int op, Type *tstruct, NodeList *nl, char *desc)
|
|||||||
// TODO(rsc): drop first if in DDD cleanup
|
// TODO(rsc): drop first if in DDD cleanup
|
||||||
if(t->etype != TINTER)
|
if(t->etype != TINTER)
|
||||||
if(checkconv(nl->n->type, t->type, 0, &xx, &yy, desc) < 0)
|
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;
|
goto out;
|
||||||
}
|
}
|
||||||
|
66
test/ddd.go
66
test/ddd.go
@ -14,6 +14,18 @@ func sum(args ...int) int {
|
|||||||
return s
|
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 {
|
func sumA(args []int) int {
|
||||||
s := 0
|
s := 0
|
||||||
for _, v := range args {
|
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 ln2(args ...T) int { return 2 * ln(args) }
|
||||||
|
|
||||||
|
func (*T) Sum(args ...int) int {
|
||||||
|
return sum(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
type U struct {
|
||||||
|
*T
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if x := sum(1, 2, 3); x != 6 {
|
if x := sum(1, 2, 3); x != 6 {
|
||||||
panicln("sum 6", x)
|
panicln("sum 6", x)
|
||||||
@ -53,6 +73,20 @@ func main() {
|
|||||||
if x := sum(1, 8); x != 9 {
|
if x := sum(1, 8); x != 9 {
|
||||||
panicln("sum 9", x)
|
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 {
|
if x := sum2(1, 2, 3); x != 2*6 {
|
||||||
panicln("sum 6", x)
|
panicln("sum 6", x)
|
||||||
}
|
}
|
||||||
@ -102,4 +136,36 @@ func main() {
|
|||||||
if x := ln2([]T{}); x != 2*1 {
|
if x := ln2([]T{}); x != 2*1 {
|
||||||
panicln("ln2 1", x)
|
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)
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ var (
|
|||||||
_ = sum(1.0, 2.0)
|
_ = sum(1.0, 2.0)
|
||||||
_ = sum(1.5) // ERROR "integer"
|
_ = sum(1.5) // ERROR "integer"
|
||||||
_ = sum("hello") // ERROR "convert"
|
_ = 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
|
type T []T
|
||||||
|
Loading…
Reference in New Issue
Block a user