p.want(_Interface)
p.want(_Lbrace)
p.list("interface type", _Semi, _Rbrace, func() bool {
- switch p.tok {
- case _Name:
- f := p.methodDecl()
- if f.Name == nil {
- f = p.embeddedElem(f)
- }
- typ.MethodList = append(typ.MethodList, f)
- return false
-
- case _Lparen:
- p.syntaxError("cannot parenthesize embedded type")
- f := new(Field)
- f.pos = p.pos()
- p.next()
- f.Type = p.qualifiedName(nil)
- p.want(_Rparen)
- typ.MethodList = append(typ.MethodList, f)
- return false
-
- case _Operator:
- if p.op == Tilde {
- typ.MethodList = append(typ.MethodList, p.embeddedElem(nil))
- return false
- }
-
- default:
- pos := p.pos()
- if t := p.typeOrNil(); t != nil {
- f := new(Field)
- f.pos = pos
- f.Type = t
- typ.MethodList = append(typ.MethodList, p.embeddedElem(f))
- return false
- }
+ var f *Field
+ if p.tok == _Name {
+ f = p.methodDecl()
}
-
- p.syntaxError("expecting method or embedded element")
- p.advance(_Semi, _Rbrace)
+ if f == nil || f.Name == nil {
+ f = p.embeddedElem(f)
+ }
+ typ.MethodList = append(typ.MethodList, f)
return false
})
--- /dev/null
+// Copyright 2022 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 p
+
+type _ interface {
+ int
+ (int)
+ (*int)
+ *([]byte)
+ ~(int)
+ (int) | (string)
+ (int) | ~(string)
+ (/* ERROR unexpected ~ */ ~int)
+ (int /* ERROR unexpected \| */ | /* ERROR unexpected string */ string /* ERROR unexpected \) */ )
+}