1
0
mirror of https://github.com/golang/go synced 2024-09-25 07:20:12 -06:00

go/types: unresolved literal keys must be looked up in universe.

Fixes #4888.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/7383051
This commit is contained in:
Rémy Oudompheng 2013-02-24 21:57:16 -08:00 committed by Robert Griesemer
parent d97b975d5c
commit 670f6b602d
2 changed files with 9 additions and 2 deletions

View File

@ -543,6 +543,8 @@ func (check *checker) compositeLitKey(key ast.Expr) {
if ident, ok := key.(*ast.Ident); ok && ident.Obj == nil {
if obj := check.pkg.Scope.Lookup(ident.Name); obj != nil {
check.register(ident, obj)
} else if obj := Universe.Lookup(ident.Name); obj != nil {
check.register(ident, obj)
} else {
check.errorf(ident.Pos(), "undeclared name: %s", ident.Name)
}

View File

@ -259,6 +259,8 @@ var index2 int = 2
func map_literals() {
type M0 map[string]int
type M1 map[bool]int
type M2 map[*int]int
_ = M0{}
_ = M0{1 /* ERROR "missing key" */ }
@ -267,11 +269,14 @@ func map_literals() {
_ = M0{"foo": 1, "bar": 2, "foo" /* ERROR "duplicate key" */ : 3 }
// map keys must be resolved correctly
// (for detials, see comment in go/parser/parser.go, method parseElement)
// (for details, see comment in go/parser/parser.go, method parseElement)
key1 := "foo"
_ = M0{key1: 1}
_ = M0{key2: 2}
_ = M0{key3 /* ERROR "undeclared name" */ : 2}
_ = M1{true: 1, false: 0}
_ = M2{nil: 0, &index2: 1}
}
var key2 string = "bar"
@ -364,4 +369,4 @@ func _calls() {
fi(g2())
fi(0, g2)
fi(0, g2 /* ERROR "2-valued expression" */ ())
}
}