Roberto Lublinerman has uploaded a new change for review.
https://gwt-review.googlesource.com/3040
Change subject: Inliner produces incorrect code if a parameter is a new
array expression.
......................................................................
Inliner produces incorrect code if a parameter is a new array expression.
The inliner incorrectly inlines a call when a parameter is a new array
expression resulting in the new array contruct beign duplicated if more
that one reference to such parameter is present.
Fixes issue 6638.
Change-Id: Ic083ac15d7d84ab4728c441fd590977cd684a87a
---
M dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
M dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java
M user/test/com/google/gwt/dev/jjs/test/CompilerMiscRegressionTest.java
3 files changed, 27 insertions(+), 0 deletions(-)
diff --git
a/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
b/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
index 2b17399..3be97ad 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ExpressionAnalyzer.java
@@ -177,6 +177,7 @@
@Override
public void endVisit(JNewArray x, Context ctx) {
+ createsObject = true;
/*
* If no array bounds, the new array is being automatically
initialized. If
* there are side-effects, they'll show up when we visit the
initializers.
diff --git
a/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java
b/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java
index 7cf1909..fb8bae5 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/ExpressionAnalyzerTest.java
@@ -168,6 +168,10 @@
analyzeExpression("boolean", "FOO =
false").accessesFieldNonFinal().hasAssignmentToField().check();
}
+ public void testNewArray() throws Exception {
+ analyzeExpression("float[]", "new float[3]").createsObject().check();
+ }
+
private Result analyzeExpression(String type, String expression)
throws UnableToCompleteException {
JProgram program = compileSnippet(type, "return " + expression + ";");
diff --git
a/user/test/com/google/gwt/dev/jjs/test/CompilerMiscRegressionTest.java
b/user/test/com/google/gwt/dev/jjs/test/CompilerMiscRegressionTest.java
index 841eec3..0ce2cd0 100644
--- a/user/test/com/google/gwt/dev/jjs/test/CompilerMiscRegressionTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/CompilerMiscRegressionTest.java
@@ -52,4 +52,26 @@
assertEquals(12.0, addAndConvert(10, "2"));
assertEquals(-10.0, minusAndDecrement(11));
}
+ private static float[] copy(float[] src, float[] dest) {
+ System.arraycopy(src, 0, dest, 0, Math.min(src.length, dest.length));
+ return dest;
+ }
+
+ /**
+ * Test for issue 6638.
+ */
+ public void testNewArrayInlining() {
+ float[] src = new float[]{1,1,1};
+ float[] dest = copy(src, new float[3]);
+
+ assertEqualContents(src, dest);
+ }
+
+ private static void assertEqualContents(float[] expected, float[]
actual) {
+
+ assertEquals("Array length mismatch", expected.length, actual.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals("Array mismatch at element " + i , expected[i],
actual[i]);
+ }
+ }
}
--
To view, visit https://gwt-review.googlesource.com/3040
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic083ac15d7d84ab4728c441fd590977cd684a87a
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.