Fixes a bad assumption in TypeTightener that the first argument of a static impl is always the this argument. Adds explicit metadata to such a parameter.
Found by: shakusa
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1610 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
index 5d6d444..f8a644b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
@@ -23,17 +23,27 @@
public class JParameter extends JVariable implements HasEnclosingMethod {
private final JMethod enclosingMethod;
+ private final boolean isThis;
JParameter(JProgram program, SourceInfo info, String name, JType type,
- boolean isFinal, JMethod enclosingMethod) {
+ boolean isFinal, boolean isThis, JMethod enclosingMethod) {
super(program, info, name, type, isFinal);
this.enclosingMethod = enclosingMethod;
+ this.isThis = isThis;
}
public JMethod getEnclosingMethod() {
return enclosingMethod;
}
+ /**
+ * Returns <code>true</code> if this parameter is the this parameter of a
+ * static impl method.
+ */
+ public boolean isThis() {
+ return isThis;
+ }
+
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
index 92b38d7..6719dcc 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
@@ -389,13 +389,13 @@
}
public JParameter createParameter(SourceInfo info, char[] name, JType type,
- boolean isFinal, JMethod enclosingMethod) {
+ boolean isFinal, boolean isThis, JMethod enclosingMethod) {
assert (name != null);
assert (type != null);
assert (enclosingMethod != null);
JParameter x = new JParameter(this, info, String.valueOf(name), type,
- isFinal, enclosingMethod);
+ isFinal, isThis, enclosingMethod);
enclosingMethod.params.add(x);
return x;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
index 30f90c9..744338e 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
@@ -188,9 +188,9 @@
// Enums have hidden arguments for name and value
if (enclosingType instanceof JEnumType) {
program.createParameter(info, "enum$name".toCharArray(),
- program.getTypeJavaLangString(), true, newMethod);
+ program.getTypeJavaLangString(), true, false, newMethod);
program.createParameter(info, "enum$ordinal".toCharArray(),
- program.getTypePrimitiveInt(), true, newMethod);
+ program.getTypePrimitiveInt(), true, false, newMethod);
}
// user args
@@ -343,7 +343,7 @@
JType type = (JType) typeMap.get(binding.type);
SourceInfo info = makeSourceInfo(binding.declaration);
JParameter param = program.createParameter(info, binding.name, type,
- binding.isFinal(), enclosingMethod);
+ binding.isFinal(), false, enclosingMethod);
typeMap.put(binding, param);
return param;
}
@@ -352,7 +352,7 @@
String argName, JMethod enclosingMethod) {
JType type = (JType) typeMap.get(arg.type);
JParameter param = program.createParameter(null, argName.toCharArray(),
- type, true, enclosingMethod);
+ type, true, false, enclosingMethod);
return param;
}
@@ -507,7 +507,7 @@
assert newMethod.getName().equals("valueOf");
assert typeMap.get(parameters[0]) == program.getTypeJavaLangString();
program.createParameter(null, "name".toCharArray(),
- program.getTypeJavaLangString(), true, newMethod);
+ program.getTypeJavaLangString(), true, false, newMethod);
} else {
assert false;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
index f5bc249..b501501 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
@@ -146,13 +146,13 @@
// Setup parameters; map from the old params to the new params
JParameter thisParam = program.createParameter(null,
- "this$static".toCharArray(), enclosingType, true, newMethod);
+ "this$static".toCharArray(), enclosingType, true, true, newMethod);
Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
for (int i = 0; i < x.params.size(); ++i) {
JParameter oldVar = x.params.get(i);
JParameter newVar = program.createParameter(oldVar.getSourceInfo(),
oldVar.getName().toCharArray(), oldVar.getType(), oldVar.isFinal(),
- newMethod);
+ false, newMethod);
varMap.put(oldVar, newVar);
}
newMethod.freezeParamTypes();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
index e6a2750..59a4448 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
@@ -158,7 +158,8 @@
new JMethodCall(program, x.getSourceInfo(), instance, program
.getNullMethod());
ctx.replaceMe(newCall);
- } else if (isStaticImpl && x.getArgs().size() > 0
+ } else if (isStaticImpl && method.params.size() > 0
+ && method.params.get(0).isThis() && x.getArgs().size() > 0
&& x.getArgs().get(0).getType() == typeNull) {
// bind null instance calls to the null method for static impls
instance = x.getArgs().get(0);