mirror of https://github.com/golang/go.git
[release-branch.go1.18] cmd/compile/internal/importer: key tparams by Package instead of pkgname
The importer type param index used package name as type parameter key,
causing type parameters to be reused/overwritten if two packages in the
import graph had the same combination of (package name, declaration
name, type parameter name).
Fix this by instead using the *Package in the key.
Note: -G=3 was added to typeparam/issue51836.go, as it is necessary for
1.18 but not for tip.
For #51836
Fixes #51847
Change-Id: I881ceaf3cf7c1ab4e0835962350feb552e79b233
Reviewed-on: https://go-review.googlesource.com/c/go/+/394219
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit fd1b5904ae)
Reviewed-on: https://go-review.googlesource.com/c/go/+/394854
This commit is contained in:
parent
c258e9d07d
commit
69bc821a01
|
|
@ -53,7 +53,7 @@ const (
|
|||
)
|
||||
|
||||
type ident struct {
|
||||
pkg string
|
||||
pkg *types2.Package
|
||||
name string
|
||||
}
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ func (r *importReader) obj(name string) {
|
|||
t := types2.NewTypeParam(tn, nil)
|
||||
// To handle recursive references to the typeparam within its
|
||||
// bound, save the partial type in tparamIndex before reading the bounds.
|
||||
id := ident{r.currPkg.Name(), name}
|
||||
id := ident{r.currPkg, name}
|
||||
r.p.tparamIndex[id] = t
|
||||
|
||||
var implicit bool
|
||||
|
|
@ -687,7 +687,7 @@ func (r *importReader) doType(base *types2.Named) types2.Type {
|
|||
errorf("unexpected type param type")
|
||||
}
|
||||
pkg, name := r.qualifiedIdent()
|
||||
id := ident{pkg.Name(), name}
|
||||
id := ident{pkg, name}
|
||||
if t, ok := r.p.tparamIndex[id]; ok {
|
||||
// We're already in the process of importing this typeparam.
|
||||
return t
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ const (
|
|||
)
|
||||
|
||||
type ident struct {
|
||||
pkg string
|
||||
pkg *types.Package
|
||||
name string
|
||||
}
|
||||
|
||||
|
|
@ -393,7 +393,7 @@ func (r *importReader) obj(name string) {
|
|||
t := types.NewTypeParam(tn, nil)
|
||||
// To handle recursive references to the typeparam within its
|
||||
// bound, save the partial type in tparamIndex before reading the bounds.
|
||||
id := ident{r.currPkg.Name(), name}
|
||||
id := ident{r.currPkg, name}
|
||||
r.p.tparamIndex[id] = t
|
||||
|
||||
var implicit bool
|
||||
|
|
@ -676,7 +676,7 @@ func (r *importReader) doType(base *types.Named) types.Type {
|
|||
errorf("unexpected type param type")
|
||||
}
|
||||
pkg, name := r.qualifiedIdent()
|
||||
id := ident{pkg.Name(), name}
|
||||
id := ident{pkg, name}
|
||||
if t, ok := r.p.tparamIndex[id]; ok {
|
||||
// We're already in the process of importing this typeparam.
|
||||
return t
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
// 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 a
|
||||
|
||||
type T[K any] struct {
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
// 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 a
|
||||
|
||||
import (
|
||||
"./a"
|
||||
)
|
||||
|
||||
type T[K any] struct {
|
||||
t a.T[K]
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// 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 p
|
||||
|
||||
import (
|
||||
a "./aa"
|
||||
)
|
||||
|
||||
var Foo a.T[int]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
// compiledir -s -G=3
|
||||
|
||||
// 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 ignored
|
||||
Loading…
Reference in New Issue