Index: user/test/com/google/gwt/dev/jjs/test/JSOBuilderPatternTest.java
===================================================================
--- user/test/com/google/gwt/dev/jjs/test/JSOBuilderPatternTest.java	(revision 0)
+++ user/test/com/google/gwt/dev/jjs/test/JSOBuilderPatternTest.java	(revision 0)
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2009 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.dev.jjs.test;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.junit.client.GWTTestCase;
+
+public class JSOBuilderPatternTest extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.dev.jjs.CompilerSuite";
+  }
+
+  // This pattern causes a failure if you use the builder pattern to set arguments.
+  private static class Builder1 extends JavaScriptObject {
+
+    protected Builder1() {
+      // required protected constructor for JSO overlay.
+    }
+
+    public static Builder1 newInstance() {
+      return createObject().cast();
+    }
+
+    public final native Builder1 setFoo(String value) /*-{
+      this.foo = value;
+      return this;
+    }-*/;
+
+    public final native Builder1 setBar(String value) /*-{
+      this.bar = value;
+      return this;      
+    }-*/;
+
+    public final native String get() /*-{
+      return this.foo + " " + this.bar;
+    }-*/;
+  }
+  
+  // Not a JSO overlay
+  private static class Builder2 {
+    String foo = "";
+    String bar = "";
+    
+    protected Builder2() {
+      // required protected constructor for JSO overlay.
+    }
+
+    public static Builder2 newInstance() {
+      return new Builder2();
+    };
+
+    public Builder2 setFoo(String value) {
+      this.foo = value;
+      return this;
+    };
+
+    public final Builder2 setBar(String value) {
+      this.bar = value;
+      return this;      
+    };
+
+    public final String get() {
+      return this.foo + " " + this.bar;
+    };
+  }
+  
+  // Make the constructor more complex to avoid inlining.
+  private static class Builder3 extends JavaScriptObject {
+
+    protected Builder3() {
+      // required protected constructor for JSO overlay.
+    }
+
+    public static native Builder3 newInstance() /*-{
+      var obj;
+      obj = new $wnd.Object();
+      return obj;
+    }-*/;
+
+    public final native Builder3 setFoo(String value) /*-{
+      this.foo = value;
+      return this;
+    }-*/;
+
+    public final native Builder3 setBar(String value) /*-{
+      this.bar = value;
+      return this;      
+    }-*/;
+
+    public final native String get() /*-{
+      return this.foo + " " + this.bar;
+    }-*/;
+  }
+  
+
+  // Fails in web mode as of r5191
+  public void testBuilder1() {
+    Builder1 b = Builder1.newInstance().setFoo("Hello").setBar("World");
+    assertEquals("newInstance().setFoo().setBar()", "Hello World", b.get());
+  }
+  
+  public void testBuilder2() {
+    Builder2 b = Builder2.newInstance().setFoo("Hello").setBar("World");
+    assertEquals("newInstance().setFoo().setBar()", "Hello World", b.get());
+  }
+  
+  public void testBuilder3() {
+    Builder3 b = Builder3.newInstance().setFoo("Hello").setBar("World");
+    assertEquals("newInstance().setFoo().setBar()", "Hello World", b.get());
+  }  
+  
+  public void testBuilderWithJSOCast() {
+    Builder1 b = JavaScriptObject.createObject().cast();
+    b.setFoo("Hello").setBar("World");
+    assertEquals("newInstance().setFoo().setBar()", "Hello World", b.get()); 
+  }
+}
