aboutsummaryrefslogtreecommitdiff
path: root/test/inline.go
diff options
context:
space:
mode:
authorTodd Neal <todd@tneal.org>2016-03-16 21:29:17 -0500
committerTodd Neal <todd@tneal.org>2016-03-21 23:05:10 +0000
commite41f527f4d56a94b33ab73efaae3575760916194 (patch)
treeadc0617cdfa94acf19cae234ea9bbbd9a29a97a7 /test/inline.go
parenta14537816eb960ae24ce13364390ded124f5ebc8 (diff)
downloadgo-e41f527f4d56a94b33ab73efaae3575760916194.tar.gz
go-e41f527f4d56a94b33ab73efaae3575760916194.zip
cmd/compile: allow inlining of functions with switch statements
Allow inlining of functions with switch statements as long as they don't contain a break or type switch. Fixes #13071 Change-Id: I057be351ea4584def1a744ee87eafa5df47a7f6d Reviewed-on: https://go-review.googlesource.com/20824 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'test/inline.go')
-rw-r--r--test/inline.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/inline.go b/test/inline.go
index 8984d059d8..e246c52e6d 100644
--- a/test/inline.go
+++ b/test/inline.go
@@ -36,3 +36,39 @@ func i(x int) int { // ERROR "can inline i"
const y = 2
return x + y
}
+
+func j(x int) int { // ERROR "can inline j"
+ switch {
+ case x > 0:
+ return x + 2
+ default:
+ return x + 1
+ }
+}
+
+// can't currently inline functions with a break statement
+func switchBreak(x, y int) int {
+ var n int
+ switch x {
+ case 0:
+ n = 1
+ Done:
+ switch y {
+ case 0:
+ n += 10
+ break Done
+ }
+ n = 2
+ }
+ return n
+}
+
+// can't currently inline functions with a type switch
+func switchType(x interface{}) int { // ERROR "switchType x does not escape"
+ switch x.(type) {
+ case int:
+ return x.(int)
+ default:
+ return 0
+ }
+}