Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 1993023003: Better boolean conversion tests. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tool/input_sdk/private/ddc_runtime/operations.dart
diff --git a/tool/input_sdk/private/ddc_runtime/operations.dart b/tool/input_sdk/private/ddc_runtime/operations.dart
index b9a324d7792a0b58e0599dda5fb1730680ddb3cc..278b2513b9510db480e134efca7fefa797e7907e 100644
--- a/tool/input_sdk/private/ddc_runtime/operations.dart
+++ b/tool/input_sdk/private/ddc_runtime/operations.dart
@@ -261,8 +261,19 @@ cast(obj, type) {
}
bool test(obj) {
- if (JS('bool', 'typeof # == "boolean"', obj)) return JS('bool', '#', obj);
- throwCastError(getReifiedType(obj), JS('', '#', bool));
+ if (obj is bool) return obj;
+ return booleanConversionFailed(obj);
+}
+
+bool booleanConversionFailed(obj) {
+ if (obj == null) {
+ throw new BooleanConversionAssertionError();
+ }
+ var actual = getReifiedType(obj);
+ var expected = JS('', '#', bool);
+ throw new TypeErrorImplementation.fromMessage(
+ "type '${typeName(actual)}' is not a subtype of "
+ "type '${typeName(expected)}' in boolean expression");
}
void _throwCastError(obj, type, bool result) {

Powered by Google App Engine
This is Rietveld 408576698