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

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java

Issue 8956047: This adds a unit test to show the type checking functionality missing in dartc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated test, $chk() can sneak in another way Created 9 years 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: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
diff --git a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
index 930133da3d7bdb1e2c5a0f1d695e5f686b90609d..ae7d902c2c8588c445e352ba137e97d261b454e8 100644
--- a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
+++ b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
@@ -1727,32 +1727,34 @@ public class GenerateJavascriptAST {
// Create the runtime type checks that will be inserted later
List<JsStatement> checks = Lists.newArrayList();
- // TODO(zundel): these runtime checks do not work in hoisted functions
- // created inside of factory methods. A bad reference to $typeArgs caused an error
- // in the closure compiler backend.
- boolean emitChecks = true;
- if (inFactory ) {
+ // TODO(zundel): Issue 925: these runtime checks do not work in hoisted functions
+ // created inside of factory methods if the parameter references type variables.
+ // A bad reference to $typeArgs caused an error in the closure compiler backend.
+ boolean omitTypeVariableChecks = false;
+ if (inFactory) {
Element element = (Element)x.getParent().getSymbol();
if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) {
// The code being emitted is something other than the factory method itself.
- emitChecks = false;
+ omitTypeVariableChecks = true;
}
}
- if (emitChecks) {
- int numParams = params.size();
- for (int i = 0; i < numParams; ++i) {
- JsNameRef jsParam = jsParams.get(i).getName().makeRef();
- DartParameter param = params.get(i);
- Type paramType = param.getSymbol().getType();
- JsExpression expr = rtt.addTypeCheck(getCurrentClass(), jsParam, paramType, null, param);
- if (expr != jsParam) {
- // if the expression was returned unchanged, omit the check
- checks.add(new JsExprStmt(expr));
- }
+ int numParams = params.size();
+ for (int i = 0; i < numParams; ++i) {
+ JsNameRef jsParam = jsParams.get(i).getName().makeRef();
+ DartParameter param = params.get(i);
+ Type paramType = param.getSymbol().getType();
+ if (omitTypeVariableChecks && TypeKind.of(paramType).equals(TypeKind.VARIABLE)) {
+ continue;
+ }
+ JsExpression expr = rtt.addTypeCheck(getCurrentClass(), jsParam, paramType, null, param);
+ if (expr != jsParam) {
+ // if the expression was returned unchanged, omit the check
+ checks.add(new JsExprStmt(expr));
}
}
+
// Add temporary variable declarations, if any.
declareTempsInBlock(body, jsNewDeclarationsStack.pop());

Powered by Google App Engine
This is Rietveld 408576698