From: Matthew Dempsky Date: Wed, 7 Sep 2022 02:28:11 +0000 (-0700) Subject: test: add failing test case for inlined type switches X-Git-Tag: go1.20rc1~1132 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=10ffb27528af47c28ee55683421056e3de5bee17;p=gostls13.git test: add failing test case for inlined type switches 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 TryBot-Result: Gopher Robot Run-TryBot: Matthew Dempsky Reviewed-by: Michael Knyszek --- diff --git a/test/fixedbugs/issue54912.dir/a.go b/test/fixedbugs/issue54912.dir/a.go new file mode 100644 index 0000000000..b425223da9 --- /dev/null +++ b/test/fixedbugs/issue54912.dir/a.go @@ -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 index 0000000000..67b9012b36 --- /dev/null +++ b/test/fixedbugs/issue54912.dir/main.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 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 index 0000000000..aefbe67310 --- /dev/null +++ b/test/fixedbugs/issue54912.go @@ -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 diff --git a/test/run.go b/test/run.go index 3c5b10ad32..ecb08ce834 100644 --- a/test/run.go +++ b/test/run.go @@ -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 )