From bd3f44e4ffe54e9cf841ebc8356e403bb38436bd Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 2 May 2023 17:37:00 +0000 Subject: cmd/compile: constant-fold loads from constant dictionaries and types Retrying the original CL with a small modification. The original CL did not handle the case of reading an itab out of a dictionary correctly. When we read an itab out of a dictionary, we must treat the type inside that itab as maybe being put in an interface. Original CL: 486895 Revert CL: 490156 Change-Id: Id2dc1699d184cd8c63dac83986a70b60b4e6cbd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/491495 Reviewed-by: Matthew Dempsky Reviewed-by: Cuong Manh Le Run-TryBot: Keith Randall Reviewed-by: Keith Randall TryBot-Result: Gopher Robot --- test/typeparam/devirtualize2.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/typeparam/devirtualize2.go (limited to 'test/typeparam/devirtualize2.go') diff --git a/test/typeparam/devirtualize2.go b/test/typeparam/devirtualize2.go new file mode 100644 index 0000000000..ca6dc8fa86 --- /dev/null +++ b/test/typeparam/devirtualize2.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2023 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 + +type S struct { + x int +} + +func (t *S) M1() { +} +func (t *S) M2() { +} + +type I interface { + M1() +} + +func F[T I](x T) I { + return x +} + +func main() { + F(&S{}).(interface{ M2() }).M2() +} -- cgit v1.3