]> Cypherpunks repositories - gostls13.git/commitdiff
test: add failing test case for inlined type switches
authorMatthew Dempsky <mdempsky@google.com>
Wed, 7 Sep 2022 02:28:11 +0000 (19:28 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 7 Sep 2022 17:26:34 +0000 (17:26 +0000)
The unified frontend ICEs when inlining a function that contains a
function literal, which captures both a type switch case variable and
another variable.

Updates #54912.

Change-Id: I0e16d371ed5df48a70823beb0bf12110a5a17266
Reviewed-on: https://go-review.googlesource.com/c/go/+/428917
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
test/fixedbugs/issue54912.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue54912.dir/main.go [new file with mode: 0644]
test/fixedbugs/issue54912.go [new file with mode: 0644]
test/run.go

diff --git a/test/fixedbugs/issue54912.dir/a.go b/test/fixedbugs/issue54912.dir/a.go
new file mode 100644 (file)
index 0000000..b425223
--- /dev/null
@@ -0,0 +1,18 @@
+// 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.
+
+// Test that inlining a function literal that captures both a type
+// switch case variable and another local variable works correctly.
+
+package a
+
+func F(p *int, x any) func() {
+       switch x := x.(type) {
+       case int:
+               return func() {
+                       *p += x
+               }
+       }
+       return nil
+}
diff --git a/test/fixedbugs/issue54912.dir/main.go b/test/fixedbugs/issue54912.dir/main.go
new file mode 100644 (file)
index 0000000..67b9012
--- /dev/null
@@ -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 main
+
+import "test/a"
+
+func main() {
+       a.F(new(int), 0)()
+}
diff --git a/test/fixedbugs/issue54912.go b/test/fixedbugs/issue54912.go
new file mode 100644 (file)
index 0000000..aefbe67
--- /dev/null
@@ -0,0 +1,7 @@
+// rundir
+
+// 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
index 3c5b10ad32c46d7e32fb8518f6986c974ed713c1..ecb08ce83496fcf20d601be384ddd406027247f6 100644 (file)
@@ -2021,6 +2021,8 @@ var unifiedFailures = setOf(
        "closure3.go", // unified IR numbers closures differently than -d=inlfuncswithclosures
        "escape4.go",  // unified IR can inline f5 and f6; test doesn't expect this
 
+       "fixedbugs/issue54912.go", // ICE when inlined type switch case variable captured in function literal
+
        "typeparam/issue47631.go", // unified IR can handle local type declarations
 )