Fixes bugs where a cloned JMethodCall fails to preserve an overridden return type.

Hopefully by adding a copy constructor, we can avoid these bugs in the future.

Review by: cromwellian

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6095 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
index c27d5ab..42559f7 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java
@@ -33,22 +33,26 @@
   private final JType overrideReturnType;
   private boolean staticDispatchOnly = false;
 
+  /**
+   * Initialize a new method call equivalent to another one. A new instance must
+   * be specified, and the new object has not arguments on initialization. This
+   * forces the caller to potentially deal with cloning objects if needed.
+   */
+  public JMethodCall(JMethodCall other, JExpression instance) {
+    super(other.getSourceInfo());
+    this.instance = instance;
+    this.cannotBePolymorphic = other.cannotBePolymorphic;
+    this.method = other.method;
+    this.overrideReturnType = other.overrideReturnType;
+    this.staticDispatchOnly = other.staticDispatchOnly;
+  }
+
   public JMethodCall(SourceInfo info, JExpression instance, JMethod method) {
     super(info);
     assert (method != null);
     assert (instance != null || method.isStatic());
     this.instance = instance;
     this.method = method;
-    this.staticDispatchOnly = false;
-    this.overrideReturnType = null;
-  }
-
-  public JMethodCall(SourceInfo info, JExpression instance, JMethod method,
-      boolean staticDispatchOnly) {
-    super(info);
-    this.instance = instance;
-    this.method = method;
-    this.staticDispatchOnly = staticDispatchOnly;
     this.overrideReturnType = null;
   }
 
@@ -66,6 +70,8 @@
   public JMethodCall(SourceInfo info, JExpression instance, JMethod method,
       JType overrideReturnType) {
     super(info);
+    assert (method != null);
+    assert (instance != null || method.isStatic());
     this.instance = instance;
     this.method = method;
     assert (overrideReturnType != null);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
index f4c5a2d..5c7de38 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java
@@ -219,14 +219,9 @@
 
   @Override
   public boolean visit(JMethodCall x, Context ctx) {
-    JMethodCall newMethodCall = new JMethodCall(x.getSourceInfo(),
-        cloneExpression(x.getInstance()), x.getTarget());
-    if (!x.canBePolymorphic()) {
-      newMethodCall.setCannotBePolymorphic();
-    }
-
+    JMethodCall newMethodCall = new JMethodCall(x,
+        cloneExpression(x.getInstance()));
     newMethodCall.addArgs(cloneExpressions(x.getArgs()));
-
     expression = newMethodCall;
     return false;
   }
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 91d04b8..a6fb2b4 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
@@ -189,12 +189,7 @@
         // This must be a static method
         assert method.isStatic();
 
-        JMethodCall newCall = new JMethodCall(x.getSourceInfo(),
-            x.getInstance(), method);
-        if (!x.canBePolymorphic()) {
-          newCall.setCannotBePolymorphic();
-        }
-
+        JMethodCall newCall = new JMethodCall(x, x.getInstance());
         List<JParameter> originalParams = methodToOriginalParamsMap.get(method);
         JMultiExpression currentMulti = null;
         for (int i = 0, c = x.getArgs().size(); i < c; ++i) {