Little fix in Pruner: check variable type after Pruner.
In the cleanup pass after pruner, if the type of a variable
is a pruned type, set the type to be JNullType.
Change-Id: I1f6b80d57e71fb03d91bfc2c8edbcf2f1337dbb4
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
index 5192781..f1b4fac 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java
@@ -89,7 +89,8 @@
* Remove assignments to pruned fields, locals and params. Nullify the return
* type of methods declared to return a globally uninstantiable type. Replace
* references to pruned variables and methods by references to the null field
- * and null method, and drop assignments to pruned variables.
+ * and null method, assignments to pruned variables, and nullify the type of
+ * variable whose type is a pruned type.
*/
private class CleanupRefsVisitor extends JModVisitorWithTemporaryVariableCreation {
private final Stack<JExpression> lValues = new Stack<JExpression>();
@@ -237,6 +238,15 @@
}
@Override
+ public void exit(JVariable x, Context ctx) {
+ JType type = x.getType();
+ if (type instanceof JReferenceType &&
+ !program.typeOracle.isInstantiatedType((JReferenceType) type)) {
+ x.setType(program.getTypeNull());
+ }
+ }
+
+ @Override
public boolean visit(JBinaryOperation x, Context ctx) {
if (x.getOp() == JBinaryOperator.ASG) {
lValues.push(x.getLhs());
diff --git a/dev/core/test/com/google/gwt/dev/jjs/impl/PrunerTest.java b/dev/core/test/com/google/gwt/dev/jjs/impl/PrunerTest.java
index 6e71b96..f74d570 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/PrunerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/PrunerTest.java
@@ -198,6 +198,15 @@
assertNotNull(result.findClass("EntryPoint$JsProtoImpl2"));
}
+ public void testCleanupVariableOfNonReferencedType() throws Exception {
+ runDeadCodeElimination = false;
+ addSnippetClassDecl("static class A {}");
+ addSnippetClassDecl("static boolean fun(A a) { return a == null; }");
+ Result result = optimize("void", "fun(null);");
+ assertNull(result.findClass("EntryPoint$A"));
+ assertEquals("static boolean fun(null a);\n", result.findMethod("fun").toString());
+ }
+
/**
* Test for issue 2478.
*/