@@ -75,7 +75,8 @@ public Collection<? extends Snippet> createValueConstructors(Context context) {
75
75
// Interop Primitives
76
76
vals .add (createValueConstructor (context , "nil" , NULL )); // should also be OBJECT?
77
77
vals .add (createValueConstructor (context , "false" , BOOLEAN ));
78
- // NOTE: NUMBER is only for primitives and types which are instanceof java.lang.Number.
78
+ // NOTE: NUMBER means InteropLibrary#isNumber
79
+ vals .add (createValueConstructor (context , "0" , NUMBER ));
79
80
vals .add (createValueConstructor (context , "7" , NUMBER )); // int
80
81
vals .add (createValueConstructor (context , "1 << 42" , NUMBER )); // long
81
82
vals .add (createValueConstructor (context , "1 << 84" , NUMBER )); // Bignum
@@ -118,7 +119,16 @@ public Collection<? extends Snippet> createExpressions(Context context) {
118
119
// ops.add(createBinaryOperator(context, "a * b", NUMBER, NUMBER, NUMBER));
119
120
// ops.add(createBinaryOperator(context, "a * b", STRING, NUMBER, STRING));
120
121
// ops.add(createBinaryOperator(context, "a * b", ARRAY, NUMBER, ARRAY));
121
- ops .add (createBinaryOperator (context , "a / b" , NUMBER , NUMBER , NUMBER ));
122
+ ops .add (createBinaryOperator (context , "a / b" , NUMBER , NUMBER , NUMBER , run -> {
123
+ Value rhs = run .getParameters ().get (1 );
124
+ // Ideally we should test if both LHS and RHS are integral but interop gives us no way currently
125
+ if (rhs .fitsInInt () && rhs .asInt () == 0 && run .getException () != null &&
126
+ run .getException ().getMessage ().equals ("divided by 0" )) {
127
+ // OK, division by 0 raises
128
+ } else {
129
+ ResultVerifier .getDefaultResultVerifier ().accept (run );
130
+ }
131
+ }));
122
132
// ops.add(createBinaryOperator(context, "a % b", NUMBER, NUMBER, NUMBER));
123
133
// ops.add(createBinaryOperator(context, "a ** b", NUMBER, NUMBER, NUMBER));
124
134
@@ -248,11 +258,18 @@ private Snippet createValueConstructor(Context context, String value, TypeDescri
248
258
249
259
private Snippet createBinaryOperator (Context context , String operator , TypeDescriptor lhsType ,
250
260
TypeDescriptor rhsType , TypeDescriptor returnType ) {
261
+ return createBinaryOperator (context , operator , lhsType , rhsType , returnType ,
262
+ ResultVerifier .getDefaultResultVerifier ());
263
+ }
264
+
265
+ private Snippet createBinaryOperator (Context context , String operator , TypeDescriptor lhsType ,
266
+ TypeDescriptor rhsType , TypeDescriptor returnType , ResultVerifier resultVerifier ) {
251
267
final Value function = context .eval (getId (), String .format ("-> a, b { %s }" , operator ));
252
268
253
269
return Snippet
254
270
.newBuilder (operator , function , returnType )
255
271
.parameterTypes (lhsType , rhsType )
272
+ .resultVerifier (resultVerifier )
256
273
.build ();
257
274
}
258
275
0 commit comments