@@ -48,6 +48,11 @@ class ExpressionTypeCheckingSuite extends FunSuite {
48
48
SimpleAnalyzer .checkAnalysis(analyzed)
49
49
}
50
50
51
+ def assertErrorForDifferingTypes (expr : Expression ): Unit = {
52
+ assertError(expr,
53
+ s " differing types in ${expr.getClass.getSimpleName} (IntegerType and BooleanType). " )
54
+ }
55
+
51
56
test(" check types for unary arithmetic" ) {
52
57
assertError(UnaryMinus (' stringField ), " operator - accepts numeric type" )
53
58
assertSuccess(Sqrt (' stringField )) // We will cast String to Double for sqrt
@@ -65,17 +70,16 @@ class ExpressionTypeCheckingSuite extends FunSuite {
65
70
assertSuccess(Remainder (' intField , ' stringField ))
66
71
// checkAnalysis(BitwiseAnd('intField, 'stringField))
67
72
68
- def msg (caller : String ) = s " differing types in $caller, IntegerType != BooleanType "
69
- assertError(Add (' intField , ' booleanField ), msg(" Add" ))
70
- assertError(Subtract (' intField , ' booleanField ), msg(" Subtract" ))
71
- assertError(Multiply (' intField , ' booleanField ), msg(" Multiply" ))
72
- assertError(Divide (' intField , ' booleanField ), msg(" Divide" ))
73
- assertError(Remainder (' intField , ' booleanField ), msg(" Remainder" ))
74
- assertError(BitwiseAnd (' intField , ' booleanField ), msg(" BitwiseAnd" ))
75
- assertError(BitwiseOr (' intField , ' booleanField ), msg(" BitwiseOr" ))
76
- assertError(BitwiseXor (' intField , ' booleanField ), msg(" BitwiseXor" ))
77
- assertError(MaxOf (' intField , ' booleanField ), msg(" MaxOf" ))
78
- assertError(MinOf (' intField , ' booleanField ), msg(" MinOf" ))
73
+ assertErrorForDifferingTypes(Add (' intField , ' booleanField ))
74
+ assertErrorForDifferingTypes(Subtract (' intField , ' booleanField ))
75
+ assertErrorForDifferingTypes(Multiply (' intField , ' booleanField ))
76
+ assertErrorForDifferingTypes(Divide (' intField , ' booleanField ))
77
+ assertErrorForDifferingTypes(Remainder (' intField , ' booleanField ))
78
+ assertErrorForDifferingTypes(BitwiseAnd (' intField , ' booleanField ))
79
+ assertErrorForDifferingTypes(BitwiseOr (' intField , ' booleanField ))
80
+ assertErrorForDifferingTypes(BitwiseXor (' intField , ' booleanField ))
81
+ assertErrorForDifferingTypes(MaxOf (' intField , ' booleanField ))
82
+ assertErrorForDifferingTypes(MinOf (' intField , ' booleanField ))
79
83
80
84
assertError(Add (' booleanField , ' booleanField ), " operator + accepts numeric type" )
81
85
assertError(Subtract (' booleanField , ' booleanField ), " operator - accepts numeric type" )
@@ -102,19 +106,24 @@ class ExpressionTypeCheckingSuite extends FunSuite {
102
106
assertSuccess(GreaterThan (' intField , ' stringField ))
103
107
assertSuccess(GreaterThanOrEqual (' intField , ' stringField ))
104
108
105
- def msg (caller : String ) = s " differing types in $caller, IntegerType != BooleanType "
106
- assertError(LessThan (' intField , ' booleanField ), msg(" LessThan" ))
107
- assertError(LessThanOrEqual (' intField , ' booleanField ), msg(" LessThanOrEqual" ))
108
- assertError(GreaterThan (' intField , ' booleanField ), msg(" GreaterThan" ))
109
- assertError(GreaterThanOrEqual (' intField , ' booleanField ), msg(" GreaterThanOrEqual" ))
110
-
111
- assertError(LessThan (' complexField , ' complexField ), " operator < accepts non-complex type" )
112
- assertError(LessThanOrEqual (' complexField , ' complexField ), " operator <= accepts non-complex type" )
113
- assertError(GreaterThan (' complexField , ' complexField ), " operator > accepts non-complex type" )
114
- assertError(GreaterThanOrEqual (' complexField , ' complexField ), " operator >= accepts non-complex type" )
115
-
116
- assertError(If (' intField , ' stringField , ' stringField ), " type of predicate expression in If should be boolean" )
117
- assertError(If (' booleanField , ' intField , ' stringField ), " differing types in If, IntegerType != StringType" )
109
+ assertErrorForDifferingTypes(LessThan (' intField , ' booleanField ))
110
+ assertErrorForDifferingTypes(LessThanOrEqual (' intField , ' booleanField ))
111
+ assertErrorForDifferingTypes(GreaterThan (' intField , ' booleanField ))
112
+ assertErrorForDifferingTypes(GreaterThanOrEqual (' intField , ' booleanField ))
113
+
114
+ assertError(
115
+ LessThan (' complexField , ' complexField ), " operator < accepts non-complex type" )
116
+ assertError(
117
+ LessThanOrEqual (' complexField , ' complexField ), " operator <= accepts non-complex type" )
118
+ assertError(
119
+ GreaterThan (' complexField , ' complexField ), " operator > accepts non-complex type" )
120
+ assertError(
121
+ GreaterThanOrEqual (' complexField , ' complexField ), " operator >= accepts non-complex type" )
122
+
123
+ assertError(
124
+ If (' intField , ' stringField , ' stringField ),
125
+ " type of predicate expression in If should be boolean" )
126
+ assertErrorForDifferingTypes(If (' booleanField , ' intField , ' booleanField ))
118
127
119
128
// Will write tests for CaseWhen later,
120
129
// as the error reporting of it is not handle by the new interface for now
0 commit comments