forked from TrueCloudLab/neoneo-go
compiler: allow to use switch
without tag
This commit is contained in:
parent
e58616b975
commit
354645fbe3
2 changed files with 22 additions and 3 deletions
|
@ -578,9 +578,13 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case *ast.SwitchStmt:
|
case *ast.SwitchStmt:
|
||||||
|
eqOpcode := opcode.EQUAL
|
||||||
|
if n.Tag != nil {
|
||||||
ast.Walk(c, n.Tag)
|
ast.Walk(c, n.Tag)
|
||||||
|
eqOpcode, _ = convertToken(token.EQL, c.typeOf(n.Tag))
|
||||||
eqOpcode, _ := convertToken(token.EQL, c.typeOf(n.Tag))
|
} else {
|
||||||
|
emit.Bool(c.prog.BinWriter, true)
|
||||||
|
}
|
||||||
switchEnd, label := c.generateLabel(labelEnd)
|
switchEnd, label := c.generateLabel(labelEnd)
|
||||||
|
|
||||||
lastSwitch := c.currentSwitch
|
lastSwitch := c.currentSwitch
|
||||||
|
|
|
@ -18,6 +18,21 @@ var switchTestCases = []testCase{
|
||||||
}`,
|
}`,
|
||||||
big.NewInt(2),
|
big.NewInt(2),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"switch with no tag",
|
||||||
|
`package main
|
||||||
|
func f() bool { return false }
|
||||||
|
func Main() int {
|
||||||
|
switch {
|
||||||
|
case f():
|
||||||
|
return 1
|
||||||
|
case true:
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
return 3
|
||||||
|
}`,
|
||||||
|
big.NewInt(2),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"simple switch fail",
|
"simple switch fail",
|
||||||
`package main
|
`package main
|
||||||
|
|
Loading…
Reference in a new issue