Commit 87c35d8d authored by Daniel Morsing's avatar Daniel Morsing

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
parent d7b7957d
......@@ -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);
......
// 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"
}
}
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