case OADDR:
if(top != Erv)
goto nottop;
+ if(n->left->op == OCONV && iscomposite(n->left->type)) {
+ // turn &Point{1, 2} into allocation.
+ // initialize with
+ // nvar := new(Point);
+ // *nvar = Point{1, 2};
+ // and replace expression with nvar
+
+ // TODO(rsc): might do a better job (fewer copies) later
+ Node *nnew, *nvar, *nas;
+
+ walktype(n->left, Elv);
+ if(n->left == N)
+ goto ret;
+
+ nvar = nod(0, N, N);
+ tempname(nvar, ptrto(n->left->type));
+
+ nnew = nod(ONEW, N, N);
+ nnew->type = nvar->type;
+ nnew = newcompat(nnew);
+
+ nas = nod(OAS, nvar, nnew);
+ addtop = list(addtop, nas);
+
+ nas = nod(OAS, nod(OIND, nvar, N), n->left);
+ addtop = list(addtop, nas);
+
+ indir(n, nvar);
+ goto ret;
+ }
walktype(n->left, Elv);
if(n->left == N)
goto ret;
+++ /dev/null
-// 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
-
-var a = &[]int{1,2}; // ERROR "composite"
}
}
+type P struct { a, b int };
+func NewP(a, b int) *P {
+ return &P{a, b}
+}
+
func main() {
var t T;
t = T{0, 7.2, "hi", &t};
if len(m) != 3 { panic("m") }
eq(&[]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)});
+
+ p1 := NewP(1, 2);
+ p2 := NewP(1, 2);
+ if p1 == p2 { panic("NewP") }
}