From 82f506e8e6706efa64a186f4feec98b143c4de3e Mon Sep 17 00:00:00 2001 From: Ben Paxton Date: Thu, 23 Feb 2017 12:06:29 +0000 Subject: [PATCH] Fix panic when eliding invalid constant cases +, >, <, <=, and >= require typechecking of both operands simultaneously; constant-operand eliding did not perform this check, causing a panic. --- evaluationFailure_test.go | 12 ++++++++++++ stagePlanner.go | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/evaluationFailure_test.go b/evaluationFailure_test.go index 9c947ab..6987771 100644 --- a/evaluationFailure_test.go +++ b/evaluationFailure_test.go @@ -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", @@ -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", diff --git a/stagePlanner.go b/stagePlanner.go index 1a9f18d..3a87d48 100644 --- a/stagePlanner.go +++ b/stagePlanner.go @@ -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 {