mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile/internal/importer: key tparams by Package instead of pkgname
The importer type param index used package name type parameter key, causing type parameters to be reused/overwritten if two packages in the import graph had the same combination of (name, declaration name, type parameter name). Fix this by instead using the *Package in the key. Fixes #51836 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>
This commit is contained in:
parent
212bda0669
commit
fd1b5904ae
@ -53,7 +53,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ident struct {
|
type ident struct {
|
||||||
pkg string
|
pkg *types2.Package
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ func (r *importReader) obj(name string) {
|
|||||||
t := types2.NewTypeParam(tn, nil)
|
t := types2.NewTypeParam(tn, nil)
|
||||||
// To handle recursive references to the typeparam within its
|
// To handle recursive references to the typeparam within its
|
||||||
// bound, save the partial type in tparamIndex before reading the bounds.
|
// 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
|
r.p.tparamIndex[id] = t
|
||||||
|
|
||||||
var implicit bool
|
var implicit bool
|
||||||
@ -687,7 +687,7 @@ func (r *importReader) doType(base *types2.Named) types2.Type {
|
|||||||
errorf("unexpected type param type")
|
errorf("unexpected type param type")
|
||||||
}
|
}
|
||||||
pkg, name := r.qualifiedIdent()
|
pkg, name := r.qualifiedIdent()
|
||||||
id := ident{pkg.Name(), name}
|
id := ident{pkg, name}
|
||||||
if t, ok := r.p.tparamIndex[id]; ok {
|
if t, ok := r.p.tparamIndex[id]; ok {
|
||||||
// We're already in the process of importing this typeparam.
|
// We're already in the process of importing this typeparam.
|
||||||
return t
|
return t
|
||||||
|
@ -53,7 +53,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ident struct {
|
type ident struct {
|
||||||
pkg string
|
pkg *types.Package
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ func (r *importReader) obj(name string) {
|
|||||||
t := types.NewTypeParam(tn, nil)
|
t := types.NewTypeParam(tn, nil)
|
||||||
// To handle recursive references to the typeparam within its
|
// To handle recursive references to the typeparam within its
|
||||||
// bound, save the partial type in tparamIndex before reading the bounds.
|
// 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
|
r.p.tparamIndex[id] = t
|
||||||
|
|
||||||
var implicit bool
|
var implicit bool
|
||||||
@ -676,7 +676,7 @@ func (r *importReader) doType(base *types.Named) types.Type {
|
|||||||
errorf("unexpected type param type")
|
errorf("unexpected type param type")
|
||||||
}
|
}
|
||||||
pkg, name := r.qualifiedIdent()
|
pkg, name := r.qualifiedIdent()
|
||||||
id := ident{pkg.Name(), name}
|
id := ident{pkg, name}
|
||||||
if t, ok := r.p.tparamIndex[id]; ok {
|
if t, ok := r.p.tparamIndex[id]; ok {
|
||||||
// We're already in the process of importing this typeparam.
|
// We're already in the process of importing this typeparam.
|
||||||
return t
|
return t
|
||||||
|
8
test/typeparam/issue51836.dir/a.go
Normal file
8
test/typeparam/issue51836.dir/a.go
Normal file
@ -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 {
|
||||||
|
}
|
13
test/typeparam/issue51836.dir/aa.go
Normal file
13
test/typeparam/issue51836.dir/aa.go
Normal file
@ -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]
|
||||||
|
}
|
11
test/typeparam/issue51836.dir/p.go
Normal file
11
test/typeparam/issue51836.dir/p.go
Normal file
@ -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]
|
7
test/typeparam/issue51836.go
Normal file
7
test/typeparam/issue51836.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// compiledir -s
|
||||||
|
|
||||||
|
// 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…
x
Reference in New Issue
Block a user