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

Unified Diff: frog/value.dart

Issue 8534001: Adds typechecking of return values (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 9 years, 1 month 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: frog/value.dart
diff --git a/frog/value.dart b/frog/value.dart
index 88f93f42769417e3fa50646bfe3b878c9ba76927..476222928ff99c4ae5aedc1a318611c5f38d4048 100644
--- a/frog/value.dart
+++ b/frog/value.dart
@@ -37,6 +37,12 @@ class Value {
/** Is this value a constant expression? */
bool get isConst() => false;
+ /**
+ * A canonicalized form of the code. Two const expressions that result in the
+ * same instance should have the same [canonicalCode].
+ */
+ String get canonicalCode() => null;
Siggi Cherem (dart-lang) 2011/11/11 08:23:53 maybe this should throw an error in this case?
+
// TODO(jimhug): Fix these names once get/set are truly pseudo-keywords.
// See issue #379.
Value get_(MethodGenerator context, String name, Node node) {
@@ -328,7 +334,15 @@ class Value {
// We rely on the fact that calling an undefined method produces a JS
// TypeError. Alternatively we could define fallbacks on Object that throw.
String check;
- if (toType.library.isCore && toType.typeofName != null) {
+ if (toType.isVoid) {
+ check = '\$assert_void($code)';
+ if (toType.typeCheckCode == null) {
jimhug 2011/11/11 15:02:02 Hmm, I'd rather not see this code sitting in value
+ toType.typeCheckCode = '''
+function \$assert_void(x) {
+ return x == null ? x : x.is\$void(); // throws TypeError
+}''';
+ }
+ } else if (toType.library.isCore && toType.typeofName != null) {
check = '\$assert_${toType.name}($code)';
if (toType.typeCheckCode == null) {

Powered by Google App Engine
This is Rietveld 408576698