Make sure a method and constructor cannot have the same signature.
Currently, a constructor has the same signature as a method with the same
name and arguments and a return type of 'void'. This causes issues in
UnifyAst which uses the signature as a key in a map. To make them different
the signature of a constructor no longer includes a return type and is annotated
with the string "<init>"; the signature for the default constructor of the Foo
class will thus now be "Foo() <init>" instead of "Foo()V".
Fixes issue 7824
Change-Id: Iebcd7d0060bf7ac39c59e316b7d6dfb4c9727d7e
Review-Link: https://gwt-review.googlesource.com/#/c/1330/
Review by: skybrian@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11464 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java
index 6864453..1986666 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JConstructor.java
@@ -74,6 +74,11 @@
return getEnclosingType().getNonNull();
}
+ @Override
+ public boolean isConstructor() {
+ return true;
+ }
+
/**
* Returns <code>true</code> if this constructor does no real work.
*
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
index 1f23013..dede802 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
@@ -249,7 +249,11 @@
sb.append(type.getJsniSignatureName());
}
sb.append(')');
- sb.append(getOriginalReturnType().getJsniSignatureName());
+ if (!isConstructor()) {
+ sb.append(getOriginalReturnType().getJsniSignatureName());
+ } else {
+ sb.append(" <init>");
+ }
signature = sb.toString();
}
return signature;
@@ -267,6 +271,10 @@
return isAbstract;
}
+ public boolean isConstructor() {
+ return false;
+ }
+
public boolean isDefault() {
return access == AccessModifier.DEFAULT.ordinal();
}
diff --git a/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java b/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
index 05ab357..4107144 100644
--- a/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
@@ -16,6 +16,7 @@
package com.google.gwt.dev.jjs.test;
import com.google.gwt.core.client.JavaScriptException;
+import com.google.gwt.dev.jjs.test.compilertests.MethodNamedSameAsClass;
import com.google.gwt.junit.client.GWTTestCase;
import junit.framework.Assert;
@@ -968,6 +969,14 @@
assertEquals(result, "foofoofoofoo");
}
+ /**
+ * test for issue 7824.
+ */
+ public void testMethodNamedSameAsClass() {
+ MethodNamedSameAsClass obj = new MethodNamedSameAsClass();
+ obj.MethodNamedSameAsClass();
+ }
+
public void testNotOptimizations() {
assertFalse(!true);
assertTrue(!false);
diff --git a/user/test/com/google/gwt/dev/jjs/test/compilertests/MethodNamedSameAsClass.java b/user/test/com/google/gwt/dev/jjs/test/compilertests/MethodNamedSameAsClass.java
new file mode 100644
index 0000000..bdfe2f8
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/test/compilertests/MethodNamedSameAsClass.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2013 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.compilertests;
+
+/**
+ * Test for issue 7824
+ */
+public class MethodNamedSameAsClass {
+ public void MethodNamedSameAsClass() { }
+}