@@ -21,9 +21,8 @@ object ExprEvaluate {
2121 case (RangeValue (lhsMin, lhsMax), RangeValue (rhsMin, rhsMax)) =>
2222 val all = Seq (lhsMin + rhsMin, lhsMin + rhsMax, lhsMax + rhsMin, lhsMax + rhsMax)
2323 RangeValue (all.min, all.max)
24- case (RangeEmpty , RangeEmpty ) => RangeEmpty
25- case (lhs : RangeValue , RangeEmpty ) => lhs
26- case (RangeEmpty , rhs : RangeValue ) => rhs
24+ case (_ : RangeType , RangeEmpty ) => RangeEmpty
25+ case (RangeEmpty , _ : RangeType ) => RangeEmpty
2726 case (RangeValue (lhsMin, lhsMax), FloatPromotable (rhs)) =>
2827 RangeValue (lhsMin + rhs, lhsMax + rhs)
2928 case (FloatPromotable (lhs), RangeValue (rhsMin, rhsMax)) =>
@@ -39,9 +38,8 @@ object ExprEvaluate {
3938 case (RangeValue (lhsMin, lhsMax), RangeValue (rhsMin, rhsMax)) =>
4039 val all = Seq (lhsMin * rhsMin, lhsMin * rhsMax, lhsMax * rhsMin, lhsMax * rhsMax)
4140 RangeValue (all.min, all.max)
42- case (RangeEmpty , RangeEmpty ) => RangeEmpty
43- case (lhs : RangeValue , RangeEmpty ) => RangeEmpty
44- case (RangeEmpty , rhs : RangeValue ) => RangeEmpty
41+ case (_ : RangeType , RangeEmpty ) => RangeEmpty
42+ case (RangeEmpty , _ : RangeType ) => RangeEmpty
4543 case (RangeValue (lhsMin, lhsMax), FloatPromotable (rhs)) if rhs >= 0 =>
4644 RangeValue (lhsMin * rhs, lhsMax * rhs)
4745 case (RangeValue (lhsMin, lhsMax), FloatPromotable (rhs)) if rhs < 0 =>
@@ -170,8 +168,8 @@ object ExprEvaluate {
170168 }
171169
172170 case Op .INTERSECTION => (lhs, rhs) match {
173- case (RangeEmpty , _) => RangeEmpty // anything intersecting with empty is empty
174- case (_, RangeEmpty ) => RangeEmpty
171+ case (RangeEmpty , _ : RangeType ) => RangeEmpty // anything intersecting with empty is empty
172+ case (_ : RangeType , RangeEmpty ) => RangeEmpty
175173 case (RangeValue (lhsMin, lhsMax), RangeValue (rhsMin, rhsMax)) =>
176174 val (minMax, maxMin) = (math.min(lhsMax, rhsMax), math.max(lhsMin, rhsMin))
177175 if (maxMin <= minMax) {
@@ -305,7 +303,10 @@ object ExprEvaluate {
305303 case (Op .SUM , ArrayValue .ExtractBoolean (vals)) => IntValue (vals.count(_ == true ))
306304 case (Op .SUM , ArrayValue .UnpackRange (extracted)) => extracted match {
307305 case ArrayValue .UnpackRange .FullRange (valMins, valMaxs) => RangeValue (valMins.sum, valMaxs.sum)
308- case _ => ErrorValue (" unpack_range(empty) is undefined" )
306+ case ArrayValue .UnpackRange .RangeWithEmpty (_, _) => RangeEmpty
307+ case ArrayValue .UnpackRange .EmptyRange () => RangeEmpty
308+ case ArrayValue .UnpackRange .EmptyArray () =>
309+ RangeValue (0 , 0 ) // unreachable in practice, superseded by float 0 case
309310 }
310311
311312 case (Op .ALL_TRUE , ArrayValue .Empty (_)) => BooleanValue (true )
@@ -340,8 +341,9 @@ object ExprEvaluate {
340341 } else { // does not intersect, null set
341342 ErrorValue (f " intersection( $extracted) produces empty set " )
342343 }
344+ case ArrayValue .UnpackRange .RangeWithEmpty (_, _) => RangeEmpty
345+ case ArrayValue .UnpackRange .EmptyRange () => RangeEmpty
343346 // The implicit initial value of intersect is the full range
344- // TODO are these good semantics?
345347 case ArrayValue .UnpackRange .EmptyArray () => RangeValue (Float .NegativeInfinity , Float .PositiveInfinity )
346348 case _ => ErrorValue (f " intersection( $vals) is undefined " )
347349 }
@@ -350,8 +352,8 @@ object ExprEvaluate {
350352 case (Op .HULL , ArrayValue .UnpackRange (extracted)) => extracted match {
351353 case ArrayValue .UnpackRange .FullRange (valMins, valMaxs) => RangeValue (valMins.min, valMaxs.max)
352354 case ArrayValue .UnpackRange .RangeWithEmpty (valMins, valMaxs) => RangeValue (valMins.min, valMaxs.max)
353- case ArrayValue .UnpackRange .EmptyArray () => RangeEmpty // TODO: should this be an error?
354355 case ArrayValue .UnpackRange .EmptyRange () => RangeEmpty
356+ case ArrayValue .UnpackRange .EmptyArray () => RangeEmpty // TODO: should this be an error?
355357 }
356358 case (Op .HULL , ArrayValue .ExtractFloat (vals)) => RangeValue (vals.min, vals.max)
357359
0 commit comments