mirror of https://github.com/golang/go.git
cmd/gc: Don't accept qualified names as literal keys
Fixes #4067. R=golang-dev, minux.ma, dave, rsc CC=golang-dev https://golang.org/cl/6622056
This commit is contained in:
parent
d7b7957db1
commit
87c35d8df1
|
|
@ -2136,7 +2136,7 @@ typecheckcomplit(Node **np)
|
|||
Node *l, *n, *r, **hash;
|
||||
NodeList *ll;
|
||||
Type *t, *f;
|
||||
Sym *s;
|
||||
Sym *s, *s1;
|
||||
int32 lno;
|
||||
ulong nhash;
|
||||
Node *autohash[101];
|
||||
|
|
@ -2302,9 +2302,11 @@ typecheckcomplit(Node **np)
|
|||
// Sym might have resolved to name in other top-level
|
||||
// package, because of import dot. Redirect to correct sym
|
||||
// before we do the lookup.
|
||||
if(s->pkg != localpkg && exportname(s->name))
|
||||
s = lookup(s->name);
|
||||
|
||||
if(s->pkg != localpkg && exportname(s->name)) {
|
||||
s1 = lookup(s->name);
|
||||
if(s1->origpkg == s->pkg)
|
||||
s = s1;
|
||||
}
|
||||
f = lookdot1(nil, s, t, t->type, 0);
|
||||
if(f == nil) {
|
||||
yyerror("unknown %T field '%S' in struct literal", t, s);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
// errorcheck
|
||||
|
||||
// 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 main
|
||||
|
||||
import "os"
|
||||
|
||||
type T struct {
|
||||
File int
|
||||
}
|
||||
|
||||
func main() {
|
||||
_ = T {
|
||||
os.File: 1, // ERROR "unknown T field"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue