"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
+ "cmd/internal/src"
)
// crawlExports crawls the type/object graph rooted at the given list of exported
if t.IsFullyInstantiated() && !t.HasShape() && !t.IsInterface() && t.Methods().Len() > 0 {
// For any fully-instantiated type, the relevant
// dictionaries and shape instantiations will have
- // already been created. Make sure that they are
- // exported, so that any other package that inlines
- // this function will have them available for import,
- // and so will not need another round of method and
- // dictionary instantiation after inlining.
+ // already been created or are in the import data.
+ // Make sure that they are exported, so that any
+ // other package that inlines this function will have
+ // them available for import, and so will not need
+ // another round of method and dictionary
+ // instantiation after inlining.
baseType := t.OrigSym().Def.(*ir.Name).Type()
shapes := make([]*types.Type, len(t.RParams()))
for i, t1 := range t.RParams() {
for j := range t.Methods().Slice() {
baseNname := baseType.Methods().Slice()[j].Nname.(*ir.Name)
dictsym := MakeDictSym(baseNname.Sym(), t.RParams(), true)
+ if dictsym.Def == nil {
+ in := Resolve(ir.NewIdent(src.NoXPos, dictsym))
+ dictsym = in.Sym()
+ }
Export(dictsym.Def.(*ir.Name))
methsym := MakeFuncInstSym(baseNname.Sym(), shapes, false, true)
+ if methsym.Def == nil {
+ in := Resolve(ir.NewIdent(src.NoXPos, methsym))
+ methsym = in.Sym()
+ }
methNode := methsym.Def.(*ir.Name)
Export(methNode)
if HaveInlineBody(methNode.Func) {
var typecheckdefstack []*ir.Name
-// Resolve ONONAME to definition, if any.
+// Resolve resolves an ONONAME node to a definition, if any. If n is not an ONONAME node,
+// Resolve returns n unchanged. If n is an ONONAME node and not in the same package,
+// then n.Sym() is resolved using import data. Otherwise, Resolve returns
+// n.Sym().Def. An ONONAME node can be created using ir.NewIdent(), so an imported
+// symbol can be resolved via Resolve(ir.NewIdent(src.NoXPos, sym)).
func Resolve(n ir.Node) (res ir.Node) {
if n == nil || n.Op() != ir.ONONAME {
return n
"typeparam/typeswitch2.go", // duplicate case failure due to stenciling
"typeparam/typeswitch3.go", // duplicate case failure due to stenciling
"typeparam/typeswitch4.go", // duplicate case failure due to stenciling
+ "typeparam/issue50552.go", // gives missing method for instantiated type
)
func setOf(keys ...string) map[string]bool {
--- /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 main
+
+import (
+ "a"
+ "fmt"
+)
+
+func BuildInt() int {
+ return a.BuildInt()
+}
+
+func main() {
+ if got, want := BuildInt(), 0; got != want {
+ panic(fmt.Sprintf("got %d, want %d", got, want))
+ }
+}