compiler: fix a bug with type conversion in switch

It was incorrectly parsed as void call.
This commit is contained in:
Evgenii Stratonikov 2020-09-02 14:48:17 +03:00
parent 7560aa345a
commit 7d61a567d5
2 changed files with 20 additions and 0 deletions

View file

@ -108,6 +108,11 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool {
if ok { if ok {
c.voidCalls[ce] = false c.voidCalls[ce] = false
} }
case *ast.SwitchStmt:
ce, ok := n.Tag.(*ast.CallExpr)
if ok {
c.voidCalls[ce] = false
}
case *ast.CaseClause: case *ast.CaseClause:
for _, e := range n.List { for _, e := range n.List {
ce, ok := e.(*ast.CallExpr) ce, ok := e.(*ast.CallExpr)

View file

@ -33,6 +33,21 @@ var switchTestCases = []testCase{
}`, }`,
big.NewInt(2), 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", "simple switch fail",
`package main `package main