Commit e41f527f authored by Todd Neal's avatar Todd Neal

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/20824Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a1453781
......@@ -888,7 +888,7 @@ func stmtfmt(n *Node) string {
f += fmt.Sprintf(" %v;", n.Ninit.First())
}
if n.Left != nil {
f += Nconv(n.Left, 0)
f += fmt.Sprintf(" %s ", Nconv(n.Left, 0))
}
f += fmt.Sprintf(" { %v }", n.List)
......
......@@ -214,10 +214,11 @@ func ishairy(n *Node, budget *int) bool {
ORANGE,
OFOR,
OSELECT,
OSWITCH,
OTYPESW,
OPROC,
ODEFER,
ODCLTYPE, // can't print yet
OBREAK,
ORETJMP:
return true
}
......
......@@ -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
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment