cmd/compile: disable type list syntax for the compiler

Add (temporary) syntax.AllowTypeLists mode to control the
acceptance of type lists; the compiler doesn't set it,
but existing syntax and types2 tests do so that the code
remains exercised while it exists.

Adjust various tests to use the type set notation.

Change-Id: I798e607912552db6bfe38a7cd4324b74c6bf4d95
Reviewed-on: https://go-review.googlesource.com/c/go/+/347249
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-09-01 17:01:26 -07:00
parent 2872496ba5
commit df4c625d88
10 changed files with 34 additions and 25 deletions

View file

@ -1448,7 +1448,7 @@ func (p *parser) interfaceType() *InterfaceType {
case _Type:
// TODO(gri) remove TypeList syntax if we accept #45346
if p.mode&AllowGenerics != 0 {
if p.mode&AllowGenerics != 0 && p.mode&AllowTypeLists != 0 {
type_ := NewName(p.pos(), "type") // cannot have a method named "type"
p.next()
if p.tok != _Semi && p.tok != _Rbrace {
@ -1484,8 +1484,13 @@ func (p *parser) interfaceType() *InterfaceType {
}
if p.mode&AllowGenerics != 0 {
p.syntaxError("expecting method, type list, or embedded element")
p.advance(_Semi, _Rbrace, _Type) // TODO(gri) remove _Type if we don't accept it anymore
if p.mode&AllowTypeLists != 0 {
p.syntaxError("expecting method, type list, or embedded element")
p.advance(_Semi, _Rbrace, _Type)
} else {
p.syntaxError("expecting method or embedded element")
p.advance(_Semi, _Rbrace)
}
return false
}