mirror of
https://github.com/golang/go
synced 2024-11-24 22:57:57 -07:00
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
This commit is contained in:
parent
1f1c9baf78
commit
6ff01f01f4
@ -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
|
||||
|
9
test/fixedbugs/bug396.dir/one.go
Normal file
9
test/fixedbugs/bug396.dir/one.go
Normal file
@ -0,0 +1,9 @@
|
||||
// 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} }
|
14
test/fixedbugs/bug396.dir/two.go
Normal file
14
test/fixedbugs/bug396.dir/two.go
Normal file
@ -0,0 +1,14 @@
|
||||
// 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)
|
||||
}
|
7
test/fixedbugs/bug396.go
Normal file
7
test/fixedbugs/bug396.go
Normal file
@ -0,0 +1,7 @@
|
||||
// $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
|
Loading…
Reference in New Issue
Block a user