return fmtprint(f, "%N{ %,H }", n->right, n->list);
case OPTRLIT:
+ if (fmtmode == FExp && n->left->right->implicit == Implicit)
+ return fmtprint(f, "%N", n->left);
return fmtprint(f, "&%N", n->left);
case OSTRUCTLIT:
if (fmtmode == FExp) { // requires special handling of field names
- fmtprint(f, "%T{", n->type);
+ if(n->right->implicit == Implicit)
+ fmtstrcpy(f, "{");
+ else
+ fmtprint(f, "%T{", n->type);
for(l=n->list; l; l=l->next) {
// another special case: if n->left is an embedded field of builtin type,
// it needs to be non-qualified. Can't figure that out in %S, so do it here
fmtprint(fp, "%O-%O%J", n->op, n->etype, n);
break;
case OTYPE:
- fmtprint(fp, "%O %S type=%T", n->op, n->sym, n->type);
+ fmtprint(fp, "%O %S%J type=%T", n->op, n->sym, n, n->type);
if(recur && n->type == T && n->ntype) {
indent(fp);
fmtprint(fp, "%O-ntype%N", n->op, n->ntype);
EscNever,
};
+enum
+{
+ Explicit,
+ Implicit, // don't print in output
+ ImplPtr, // OIND added by &T{ ... } literal
+};
+
struct Node
{
// Tree structure.
uchar used;
uchar isddd;
uchar readonly;
- uchar implicit; // don't show in printout
+ uchar implicit; // Explicit, Implicit, ImplPtr.
uchar addrtaken; // address taken, even if not moved to heap
uchar dupok; // duplicate definitions ok (for func)
// Special case for &T{...}: turn into (*T){...}.
$$ = $2;
$$->right = nod(OIND, $$->right, N);
- $$->right->implicit = 1;
+ $$->right->implicit = ImplPtr;
} else {
$$ = nod(OADDR, $2, N);
}
n->type = t;
if(isptr[t->etype]) {
- // For better or worse, we don't allow pointers as
- // the composite literal type, except when using
- // the &T syntax, which sets implicit.
- if(!n->right->implicit) {
+ // For better or worse, we don't allow pointers as the composite literal type,
+ // except when using the &T syntax, which sets implicit to ImplPtr.
+ if(n->right->implicit == Explicit) {
yyerror("invalid pointer type %T for composite literal (use &%T instead)", t, t->type);
goto error;
}
// Special case for &T{...}: turn into (*T){...}.
(yyval.node) = (yyvsp[(2) - (2)].node);
(yyval.node)->right = nod(OIND, (yyval.node)->right, N);
- (yyval.node)->right->implicit = 1;
+ (yyval.node)->right->implicit = ImplPtr;
} else {
(yyval.node) = nod(OADDR, (yyvsp[(2) - (2)].node), N);
}
// Call of inlined method with blank receiver.
func (_ *T) M() int { return 1 }
func (t *T) MM() int { return t.M() }
+
+
+// One more like issue 2678
+type S struct { x, y int }
+type U []S
+
+func F4(S int) U { return U{{S,S}} }
+
+func F5() []*S {
+ return []*S{ {1,2}, { 3, 4} }
+}
+
+func F6(S int) *U {
+ return &U{{S,S}}
+}
+
+
+
+
one.F1(nil)
one.F2(nil)
one.F3()
+ one.F4(1)
var t *one.T
t.M()