Parsing and printing support for type aliases complete.
go/types recognizes them an issues an "unimplemented" error for now.
For #18130.
Change-Id: I9f2f7b1971b527276b698d9347bcd094ef0012ee
Reviewed-on: https://go-review.googlesource.com/34986
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
TypeSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name *Ident // type name
+ Assign token.Pos // position of '=', if any
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
Comment *CommentGroup // line comments; or nil
}
// (Global identifiers are resolved in a separate phase after parsing.)
spec := &ast.TypeSpec{Doc: doc, Name: ident}
p.declare(spec, nil, p.topScope, ast.Typ, ident)
-
+ if p.tok == token.ASSIGN {
+ spec.Assign = p.pos
+ p.next()
+ }
spec.Type = p.parseType()
p.expectSemi() // call before accessing p.linecomment
spec.Comment = p.lineComment
`package p; const (x = 0; y; z)`, // issue 9639
`package p; var _ = map[P]int{P{}:0, {}:1}`,
`package p; var _ = map[*P]int{&P{}:0, {}:1}`,
+ `package p; type T = int`,
+ `package p; type (T = p.T; _ = struct{}; x = *T)`,
}
func TestValid(t *testing.T) {
} else {
p.print(vtab)
}
+ if s.Assign.IsValid() {
+ p.print(token.ASSIGN, blank)
+ }
p.expr(s.Type)
p.setComment(s.Comment)
x int
y int
}) // no extra comma between } and )
+
+// alias declarations
+
+type c0 struct{}
+type c1 = C
+type c2 = struct{ x int }
+type c3 = p.C
+type (
+ s struct{}
+ a = A
+ b = A
+ c = foo
+ d = interface{}
+ ddd = p.Foo
+)
x int
y int
}) // no extra comma between } and )
+
+// alias declarations
+
+type c0 struct{}
+type c1 = C
+type c2 = struct{ x int}
+type c3 = p.C
+type (
+ s struct{}
+ a = A
+ b = A
+ c = foo
+ d = interface{}
+ ddd = p.Foo
+)
\ No newline at end of file
}
case *ast.TypeSpec:
+ if s.Assign.IsValid() {
+ check.errorf(s.Assign, "type alias declarations not yet implemented")
+ }
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil)
// spec: "The scope of a type identifier declared inside a function
// begins at the identifier in the TypeSpec and ends at the end of
}
case *ast.TypeSpec:
+ if s.Assign.IsValid() {
+ check.errorf(s.Assign, "type alias declarations not yet implemented")
+ }
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil)
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type})
func (BlankT) _(int) {}
func (BlankT) _() int { return 0 }
func (BlankT) _(int) int { return 0}
+
+// type alias declarations
+// TODO(gri) complete this
+type (
+ __ = /* ERROR not yet implemented */ int
+ a0 = /* ERROR not yet implemented */ int
+ a1 = /* ERROR not yet implemented */ struct{}
+)