mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: fix case for structural types where we should be looking at typeparams
In getInstantiation, we were not computing tparams correctly for the case where the receiver of a method was a fully-instantiated type. This wasn't affecting later parts of the function, since method instantiations of fully-instantiated types were already being calculated in an earlier path. But it did give us a non-typeparam when trying to see if a shape was associated with a type param with a structural type. The fix is just to get the typeparams associated with the base generic type. Then we can eliminate a conditional check later in the code. The tparam parameter of Shapify should always be non-nil Fixes #51367 Change-Id: I6f95fe603886148b2dad0c581416c51373c85009 Reviewed-on: https://go-review.googlesource.com/c/go/+/388116 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
0907d57abf
commit
06a43e4ab6
5 changed files with 45 additions and 8 deletions
14
test/typeparam/issue51367.dir/a.go
Normal file
14
test/typeparam/issue51367.dir/a.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// 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 A[T any] struct{}
|
||||
|
||||
func (_ A[T]) Method() {}
|
||||
|
||||
func DoSomething[P any]() {
|
||||
a := A[*byte]{}
|
||||
a.Method()
|
||||
}
|
||||
13
test/typeparam/issue51367.dir/main.go
Normal file
13
test/typeparam/issue51367.dir/main.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 main
|
||||
|
||||
import (
|
||||
"a"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a.DoSomething[byte]()
|
||||
}
|
||||
7
test/typeparam/issue51367.go
Normal file
7
test/typeparam/issue51367.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// rundir -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…
Add table
Add a link
Reference in a new issue