Skip to content

Commit

Permalink
Merge pull request #46 from benpaxton-hf/constant-eliding
Browse files Browse the repository at this point in the history
Fix panic when eliding invalid constant cases
  • Loading branch information
Knetic authored Feb 23, 2017
2 parents 5598166 + 82f506e commit 50a86a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions evaluationFailure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func TestNilParameterUsage(test *testing.T) {
func TestModifierTyping(test *testing.T) {

evaluationTests := []EvaluationFailureTest{
EvaluationFailureTest{

Name: "PLUS literal number to literal bool",
Input: "1 + true",
Expected: INVALID_MODIFIER_TYPES,
},
EvaluationFailureTest{

Name: "PLUS number to bool",
Expand Down Expand Up @@ -242,6 +248,12 @@ func TestLogicalOperatorTyping(test *testing.T) {
func TestComparatorTyping(test *testing.T) {

evaluationTests := []EvaluationFailureTest{
EvaluationFailureTest{

Name: "GT literal bool to literal bool",
Input: "true > true",
Expected: INVALID_COMPARATOR_TYPES,
},
EvaluationFailureTest{

Name: "GT bool to bool",
Expand Down
4 changes: 4 additions & 0 deletions stagePlanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ func elideStage(root *evaluationStage) *evaluationStage {
return root
}

if root.typeCheck != nil && !root.typeCheck(leftValue, rightValue) {
return root
}

// pre-calculate, and return a new stage representing the result.
result, err = root.operator(leftValue, rightValue, nil)
if err != nil {
Expand Down

0 comments on commit 50a86a4

Please sign in to comment.