diff --git a/pkg/compiler/func_scope.go b/pkg/compiler/func_scope.go index 2eca590fe..384e14992 100644 --- a/pkg/compiler/func_scope.go +++ b/pkg/compiler/func_scope.go @@ -108,6 +108,11 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool { if ok { c.voidCalls[ce] = false } + case *ast.SwitchStmt: + ce, ok := n.Tag.(*ast.CallExpr) + if ok { + c.voidCalls[ce] = false + } case *ast.CaseClause: for _, e := range n.List { ce, ok := e.(*ast.CallExpr) diff --git a/pkg/compiler/switch_test.go b/pkg/compiler/switch_test.go index ce90ee0c2..73c711b79 100644 --- a/pkg/compiler/switch_test.go +++ b/pkg/compiler/switch_test.go @@ -33,6 +33,21 @@ var switchTestCases = []testCase{ }`, big.NewInt(2), }, + { + "type conversion in tag", + `package main + type state int + func Main() int { + a := 1 + switch state(a) { + case 1: + return 42 + default: + return 11 + } + }`, + big.NewInt(42), + }, { "simple switch fail", `package main