]> Cypherpunks repositories - gostls13.git/commitdiff
exp/types: some comment fixes
authorRobert Griesemer <gri@golang.org>
Wed, 26 Dec 2012 22:04:50 +0000 (14:04 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 26 Dec 2012 22:04:50 +0000 (14:04 -0800)
R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/7018046

src/pkg/exp/gotype/gotype_test.go
src/pkg/exp/types/expr.go
src/pkg/go/parser/parser.go

index addce418d31a57ea2a30c1a6059dd2ca565174df..755336871e56fa206d620395b359ea3e9040c35c 100644 (file)
@@ -52,8 +52,8 @@ var tests = []string{
 
        // directories
        // Note: Packages that don't typecheck yet are commented out.
-       // Unless there is comment next to the commented out packages,
-       // the package does't typecheck due to errors in the shift
+       // Unless there is comment next to the commented out packages,
+       // the package doesn't typecheck due to errors in the shift
        // expression checker.
        "archive/tar",
        "archive/zip",
index 1ac0e91db4be4016957e32452de53b3bf233893a..6e31323cb61058799a8aa428ad1576aea2a0d0de 100644 (file)
@@ -714,6 +714,14 @@ func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type, iota int, cycle
                }
 
        case *ast.CompositeLit:
+               // TODO(gri) Known bug: The parser doesn't resolve composite literal keys
+               //           because it cannot know the type of the literal and therefore
+               //           cannot know if a key is a struct field or not. Consequently,
+               //           if a key is an identifier, it is unresolved and thus has no
+               //           ast.Objects associated with it. At the moment, the respective
+               //           error message is not issued because the type-checker doesn't
+               //           resolve the identifier, and because it assumes that the parser
+               //           did the resolution.
                typ := hint
                openArray := false
                if e.Type != nil {
index 00757e0d753300944ef057777a751273852c6ee5..ad65a7bf214284a7c86ce8f23c5466219f05d312 100644 (file)
@@ -1189,14 +1189,18 @@ func (p *parser) parseElement(keyOk bool) ast.Expr {
                return p.parseLiteralValue(nil)
        }
 
-       x := p.checkExpr(p.parseExpr(keyOk)) // don't resolve if map key
+       // The parser cannot resolve a key expression because it does not know
+       // what the composite literal type is: if we have an array/slice index
+       // or map key, we want to resolve, but if we have a struct field name
+       // we cannot. Leave this to type-checking phase.
+       x := p.checkExpr(p.parseExpr(keyOk))
        if keyOk {
                if p.tok == token.COLON {
                        colon := p.pos
                        p.next()
                        return &ast.KeyValueExpr{Key: x, Colon: colon, Value: p.parseElement(false)}
                }
-               p.resolve(x) // not a map key
+               p.resolve(x) // not a key
        }
 
        return x