Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when eliding invalid constant cases #46

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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