Commit 6ff01f01 authored by Luuk van Dijk's avatar Luuk van Dijk

gc: fieldnames in structliterals in exported inlines should not be qualified if…

gc: fieldnames in structliterals in exported inlines should not be qualified if they're embedded builtin types.

Trust me.
Fixes #2687.

R=rsc
CC=golang-dev
https://golang.org/cl/5545047
parent 1f1c9baf
......@@ -1062,6 +1062,7 @@ exprfmt(Fmt *f, Node *n, int prec)
{
int nprec;
NodeList *l;
Type *t;
while(n && n->implicit)
n = n->left;
......@@ -1160,11 +1161,22 @@ exprfmt(Fmt *f, Node *n, int prec)
case OSTRUCTLIT:
if (fmtmode == FExp) { // requires special handling of field names
fmtprint(f, "%T{", n->type);
for(l=n->list; l; l=l->next)
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
if(l->n->left->type->embedded) {
t = l->n->left->type->type;
if(t->sym == S)
t = t->type;
fmtprint(f, " %T:%N", t, l->n->right);
} else
fmtprint(f, " %hhS:%N", l->n->left->sym, l->n->right);
if(l->next)
fmtprint(f, " %hhS:%N,", l->n->left->sym, l->n->right);
fmtstrcpy(f, ",");
else
fmtprint(f, " %hhS:%N ", l->n->left->sym, l->n->right);
fmtstrcpy(f, " ");
}
return fmtstrcpy(f, "}");
}
// fallthrough
......
// Copyright 2012 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 one
type T struct { int }
func New(i int) T { return T{i} }
// Copyright 2012 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.
// Use the functions in one.go so that the inlined
// forms get type-checked.
package two
import "./one"
func use() {
_ = one.New(1)
}
\ No newline at end of file
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go
// Copyright 2011 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 ignored
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment