mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
cmd/compile: fix reference to generic type needed by crawler
This problem happens when you create a new local type that uses an imported generic type (maybe just by instantiating it), and then that local type needed to be included as part of an export. In that case, the imported generic type is does not have a declaration in the local package, so it is not necessarily created in types1, so the crawler/export doesn't work. To fix this issue, we just need to add a call to g.obj() for the base generic type, to make sure that it will exist if needed later in the compilation or for the crawler during export. Fixes #47514 Change-Id: Ie756578f07ad0007de8a88ae909cf7534a22936e Reviewed-on: https://go-review.googlesource.com/c/go/+/345411 Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
eb6a07fcf9
commit
c9e05fdcf7
4 changed files with 28 additions and 1 deletions
|
@ -118,9 +118,14 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
|
|||
return s.Def.Type()
|
||||
}
|
||||
|
||||
// Make sure the base generic type exists in type1 (it may
|
||||
// not yet if we are referecing an imported generic type, as
|
||||
// opposed to a generic type declared in this package).
|
||||
_ = g.obj(typ.Orig().Obj())
|
||||
|
||||
// Create a forwarding type first and put it in the g.typs
|
||||
// map, in order to deal with recursive generic types
|
||||
// (including via method signatures).. Set up the extra
|
||||
// (including via method signatures). Set up the extra
|
||||
// ntyp information (Def, RParams, which may set
|
||||
// HasTParam) before translating the underlying type
|
||||
// itself, so we handle recursion correctly.
|
||||
|
|
5
test/typeparam/issue47514c.dir/a.go
Normal file
5
test/typeparam/issue47514c.dir/a.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package a
|
||||
|
||||
type Doer[T any] interface {
|
||||
Do() T
|
||||
}
|
10
test/typeparam/issue47514c.dir/main.go
Normal file
10
test/typeparam/issue47514c.dir/main.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import "a"
|
||||
|
||||
func Do[T any](doer a.Doer[T]) {
|
||||
doer.Do()
|
||||
}
|
||||
|
||||
func main() {
|
||||
}
|
7
test/typeparam/issue47514c.go
Normal file
7
test/typeparam/issue47514c.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
// rundir -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
|
Loading…
Reference in a new issue