Skip to content

Commit

Permalink
optimiser/evaluator: fix case expression evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Jan 15, 2016
1 parent 70bfab8 commit b6a0f5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions optimizer/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func (e *Evaluator) caseExpr(v *ast.CaseExpr) bool {
}
if v.ElseClause != nil {
v.SetValue(v.ElseClause.GetValue())
} else {
v.SetValue(nil)
}
return true
}
Expand Down
16 changes: 16 additions & 0 deletions optimizer/evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ func (s *testEvaluatorSuite) TestCaseWhen(c *C) {
},
}
s.runTests(c, cases)

// When expression value changed, result set back to null.
valExpr := ast.NewValueExpr(1)
whenClause := &ast.WhenClause{Expr: ast.NewValueExpr(1), Result: ast.NewValueExpr(1)}
caseExpr := &ast.CaseExpr{
Value: valExpr,
WhenClauses: []*ast.WhenClause{whenClause},
}
ctx := mock.NewContext()
v, err := Eval(ctx, caseExpr)
c.Assert(err, IsNil)
c.Assert(v, Equals, 1)
valExpr.SetValue(4)
v, err = Eval(ctx, caseExpr)
c.Assert(err, IsNil)
c.Assert(v, IsNil)
}

func (s *testEvaluatorSuite) TestConvert(c *C) {
Expand Down

0 comments on commit b6a0f5b

Please sign in to comment.