}
func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
+ assert(g.curDecl == "")
// Set g.curDecl to the function name, as context for the type params declared
// during types2-to-types1 translation if this is a generic function.
g.curDecl = decl.Name.Value
}
haveEmbed := g.haveEmbed
+ g.curDecl = ""
g.later(func() {
defer func(b bool) { g.haveEmbed = b }(g.haveEmbed)
}
func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
+ assert(g.curDecl == "")
// Set g.curDecl to the type name, as context for the type params declared
// during types2-to-types1 translation if this is a generic type.
g.curDecl = decl.Name.Value
assert(name.Alias()) // should be set by irgen.obj
out.Append(ir.NewDecl(g.pos(decl), ir.ODCLTYPE, name))
+ g.curDecl = ""
return
}
}
types.ResumeCheckSize()
+ g.curDecl = ""
if otyp, ok := otyp.(*types2.Named); ok && otyp.NumMethods() != 0 {
methods := make([]*types.Field, otyp.NumMethods())
for i := range methods {
meth := g.obj(m)
methods[i] = types.NewField(meth.Pos(), g.selector(m), meth.Type())
methods[i].Nname = meth
+ g.curDecl = ""
}
ntyp.Methods().Set(methods)
}
pkg := g.tpkg(typ)
// Create the unique types1 name for a type param, using its context with a
// function, type, or method declaration.
+ assert(g.curDecl != "")
nm := g.curDecl + "." + typ.Obj().Name()
sym := pkg.Lookup(nm)
if sym.Def != nil {
tparams := make([]*types.Type, rparams.Len())
// Set g.curDecl to be the method context, so type
// params in the receiver of the method that we are
- // translating gets the right unique name.
+ // translating gets the right unique name. We could
+ // be in a top-level typeDecl, so save and restore
+ // the current contents of g.curDecl.
+ savedCurDecl := g.curDecl
g.curDecl = typ.Obj().Name() + "." + m.Name()
for i := range tparams {
tparams[i] = g.typ1(rparams.At(i))
}
+ g.curDecl = savedCurDecl
assert(len(tparams) == len(targs))
ts := typecheck.Tsubster{
Tparams: tparams,
--- /dev/null
+// Copyright 2021 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 a
+
+type Option[T any] interface {
+ ToSeq() Seq[T]
+}
+
+type Seq[T any] []T
+
+func (r Seq[T]) Find(p func(v T) bool) Option[T] {
+ panic("")
+}
--- /dev/null
+// Copyright 2021 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 b
+
+import "a"
+
+type Ap1[A, B any] struct {
+ opt a.Option[A]
+}
+
+type Ap2[A, B any] struct {
+ opt a.Option[A]
+}
--- /dev/null
+// Copyright 2021 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 main
+
+import (
+ "b"
+ "fmt"
+)
+
+func main() {
+ opt := b.Ap1[string, string]{}
+ fmt.Println(opt)
+}
--- /dev/null
+// compiledir -G=3
+
+// Copyright 2021 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 ignored