diff options
| author | Dan Scales <danscales@google.com> | 2022-01-26 17:58:08 -0800 |
|---|---|---|
| committer | Dan Scales <danscales@google.com> | 2022-01-27 05:30:27 +0000 |
| commit | a991d9dc27bda23018e23488806c8f8d027e4f7b (patch) | |
| tree | f441100f1575e22ced15c4c411ef7d7156c633c5 /test/typeparam | |
| parent | f4aa021985e9ae4a9a395f8fbe32ad08d2bfda3b (diff) | |
| download | go-a991d9dc27bda23018e23488806c8f8d027e4f7b.tar.xz | |
cmd/compile: add missing shape check in (*Tsubster).tinter
Add a missing shape check in (*Tsubster).tinter when substituting on a
generic type which is an empty interface, analogous to same check in
(*Tsubster).tstruct. Empty structs/interfaces that have rparams (i.e.
are a generic type or a shape type) need to get a new type of their
rparams - they will be different even though they don't have any
fields/methods. Without this shape check, we were not correctly
completing the Token[int] type during substitution in the example in the
issue. This issue only happens for a generic type which is an empty
interface (i.e. doesn't actually use the type param, hence quite unusual).
Added the test case already created by Keith.
Fixes #50841
Change-Id: Ia985b9f52c0e87ed0647b46373e44c51cb748ba4
Reviewed-on: https://go-review.googlesource.com/c/go/+/381175
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>
Diffstat (limited to 'test/typeparam')
| -rw-r--r-- | test/typeparam/issue50841.dir/a.go | 22 | ||||
| -rw-r--r-- | test/typeparam/issue50841.dir/b.go | 11 | ||||
| -rw-r--r-- | test/typeparam/issue50841.go | 7 |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/typeparam/issue50841.dir/a.go b/test/typeparam/issue50841.dir/a.go new file mode 100644 index 0000000000..37e0233701 --- /dev/null +++ b/test/typeparam/issue50841.dir/a.go @@ -0,0 +1,22 @@ +// 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 + +func Marshal[foobar any]() { + _ = NewEncoder[foobar]() +} + +func NewEncoder[foobar any]() *Encoder[foobar] { + return nil +} + +type Encoder[foobar any] struct { +} + +func (e *Encoder[foobar]) EncodeToken(t Token[foobar]) { + +} + +type Token[foobar any] any diff --git a/test/typeparam/issue50841.dir/b.go b/test/typeparam/issue50841.dir/b.go new file mode 100644 index 0000000000..f2f70225ff --- /dev/null +++ b/test/typeparam/issue50841.dir/b.go @@ -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 b + +import "a" + +func F() { + a.Marshal[int]() +} diff --git a/test/typeparam/issue50841.go b/test/typeparam/issue50841.go new file mode 100644 index 0000000000..060a1214cc --- /dev/null +++ b/test/typeparam/issue50841.go @@ -0,0 +1,7 @@ +// compiledir -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 |
