pos := p.expect(token.INTERFACE)
lbrace := p.expect(token.LBRACE)
+
var list []*ast.Field
- for p.tok == token.IDENT || p.parseTypeParams() && (p.tok == token.TYPE || p.tok == token.TILDE) {
- switch p.tok {
- case token.IDENT:
+
+parseElements:
+ for {
+ switch {
+ case p.tok == token.IDENT:
f := p.parseMethodSpec()
if f.Names == nil && p.parseTypeParams() {
f = p.embeddedElem(f)
p.expectSemi()
f.Comment = p.lineComment
list = append(list, f)
- case token.TILDE:
+ case p.tok == token.TILDE && p.parseTypeParams():
f := p.embeddedElem(nil)
p.expectSemi()
f.Comment = p.lineComment
list = append(list, f)
- case token.TYPE:
+ case p.tok == token.TYPE && p.parseTypeParams():
// TODO(rfindley): remove TypeList syntax and refactor the clauses above.
// all types in a type list share the same field name "type"
list = append(list, &ast.Field{Names: name, Type: typ})
}
p.expectSemi()
+ case p.parseTypeParams():
+ if t := p.tryIdentOrType(); t != nil {
+ f := new(ast.Field)
+ f.Type = t
+ f = p.embeddedElem(f)
+ p.expectSemi()
+ f.Comment = p.lineComment
+ list = append(list, f)
+ } else {
+ break parseElements
+ }
+ default:
+ break parseElements
}
}
+
// TODO(rfindley): the error produced here could be improved, since we could
// accept a identifier, 'type', or a '}' at this point.
rbrace := p.expect(token.RBRACE)
`package p; func (type /* ERROR "found 'type'" */ T)(T) _()`,
`package p; type _[A+B, /* ERROR "expected ']'" */ ] int`,
- // TODO: this error should be positioned on the ':'
+ // TODO(rfindley): this error should be positioned on the ':'
`package p; var a = a[[]int:[ /* ERROR "expected expression" */ ]int];`,
- // TODO: the compiler error is better here: "cannot parenthesize embedded type"
- `package p; type I1 interface{}; type I2 interface{ (/* ERROR "expected '}', found '\('" */ I1) }`,
+
+ // TODO(rfindley): the compiler error is better here: "cannot parenthesize embedded type"
+ // TODO(rfindley): confirm that parenthesized types should now be accepted.
+ // `package p; type I1 interface{}; type I2 interface{ (/* ERROR "expected '}', found '\('" */ I1) }`,
// issue 8656
`package p; func f() (a b string /* ERROR "missing ','" */ , ok bool)`,