Add constant evaluation tests for IfNull.
Change-Id: I68229e831cea9e1c9aac548d9da8434bcacdaaff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96710
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/tests/compiler/dart2js_extra/constant_folding_test.dart b/tests/compiler/dart2js_extra/constant_folding_test.dart
index 5f62968..cc88f68 100644
--- a/tests/compiler/dart2js_extra/constant_folding_test.dart
+++ b/tests/compiler/dart2js_extra/constant_folding_test.dart
@@ -868,6 +868,11 @@
const Identity(double.negativeInfinity, double.infinity, false).check();
const Identity(double.negativeInfinity, double.negativeInfinity, true)
.check();
+
+ const IfNull(null, null, null).check();
+ const IfNull(null, 1, 1).check();
+ const IfNull("foo", 1, "foo").check();
+ const IfNull("foo", null, "foo").check();
}
/// Wraps [Expect.equals] to accommodate JS equality semantics.
@@ -1221,3 +1226,16 @@
@pragma('dart2js:tryInline')
eval() => identical(arg1, arg2);
}
+
+class IfNull extends TestOp {
+ final arg1;
+ final arg2;
+
+ const IfNull(this.arg1, this.arg2, expected) : super(expected, arg1 ?? arg2);
+
+ @pragma('dart2js:tryInline')
+ check() => checkAll(eval());
+
+ @pragma('dart2js:tryInline')
+ eval() => arg1 ?? arg2;
+}