]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/syntax: accept embedded type literals
authorRobert Griesemer <gri@golang.org>
Wed, 19 May 2021 00:37:54 +0000 (17:37 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 19 May 2021 04:19:24 +0000 (04:19 +0000)
The parser accepted embedded elements but the first term
of an element had to be a ~-term or a type name. This CL
fixes that.

Change-Id: I013b6cdc5963fb228867ca6597f9139db2be7ec5
Reviewed-on: https://go-review.googlesource.com/c/go/+/321109
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>
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/testdata/interface.go2

index e7b8840b337e679bb11e32ef844c1bf32764412a..0e711a0113fb29f238dccbfefaa7f241511550d9 100644 (file)
@@ -1443,6 +1443,18 @@ func (p *parser) interfaceType() *InterfaceType {
                                }
                                return false
                        }
+
+               default:
+                       if p.mode&AllowGenerics != 0 {
+                               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
+                               }
+                       }
                }
 
                if p.mode&AllowGenerics != 0 {
index a817327a43f4c289e55b541880974981c1b54278..b399d7514889f39c5e8889088dd2c4ada0d2c857 100644 (file)
@@ -25,7 +25,6 @@ type _ interface {
        ~int | ~string
 }
 
-
 type _ interface {
        m()
        ~int
@@ -34,3 +33,48 @@ type _ interface {
        ~int | ~string
        type bool, int, float64
 }
+
+type _ interface {
+       int
+       []byte
+       [10]int
+       struct{}
+       *int
+       func()
+       interface{}
+       map[string]int
+       chan T
+       chan<- T
+       <-chan T
+       T[int]
+}
+
+type _ interface {
+       int | string
+       []byte | string
+       [10]int | string
+       struct{} | string
+       *int | string
+       func() | string
+       interface{} | string
+       map[string]int | string
+       chan T | string
+       chan<- T | string
+       <-chan T | string
+       T[int] | string
+}
+
+type _ interface {
+       ~int | string
+       ~[]byte | string
+       ~[10]int | string
+       ~struct{} | string
+       ~*int | string
+       ~func() | string
+       ~interface{} | string
+       ~map[string]int | string
+       ~chan T | string
+       ~chan<- T | string
+       ~<-chan T | string
+       ~T[int] | string
+}