Fixes issue #1260. I introduced the bug in r955. The problem I was trying to solve in that revision was making the following code do an array store check:
FinalType ft[];
NonFinalSuper nfs;
ft[0] = nfs;
Previously, we'd fail to do a type check on account of the element type being final; but really you need the element type to be final AND the RHS static type to be the same type to elide the check.
My faulty logic caused a set to be emitted any time the element type and RHS static type differed-- even if it was a primitive array. This change makes sure primitive arrays never emit a type check.
Found by: ispeters
Review by: mmendez
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1198 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
index 726fbd9..96fc5f9 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
@@ -53,19 +53,21 @@
JArrayType arrayType = (JArrayType) arrayRef.getInstance().getType();
JType elementType = arrayType.getElementType();
- // see if we need to do a checked store
- // primitives and (effectively) final are statically correct
- if (elementType instanceof JReferenceType
- && (!((JReferenceType) elementType).isFinal())
- || elementType != x.getRhs().getType()) {
- // replace this assignment with a call to setCheck()
-
- JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
- setCheckMethod);
- call.getArgs().add(arrayRef.getInstance());
- call.getArgs().add(arrayRef.getIndexExpr());
- call.getArgs().add(x.getRhs());
- ctx.replaceMe(call);
+ /*
+ * See if we need to do a checked store. Primitives and (effectively)
+ * final are statically correct.
+ */
+ if (elementType instanceof JReferenceType) {
+ if (!((JReferenceType) elementType).isFinal()
+ || elementType != x.getRhs().getType()) {
+ // replace this assignment with a call to setCheck()
+ JMethodCall call = new JMethodCall(program, x.getSourceInfo(),
+ null, setCheckMethod);
+ call.getArgs().add(arrayRef.getInstance());
+ call.getArgs().add(arrayRef.getIndexExpr());
+ call.getArgs().add(x.getRhs());
+ ctx.replaceMe(call);
+ }
}
}
}
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 b894cb5..56aeddb 100644
--- a/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
@@ -180,6 +180,10 @@
Apple g = noOptimizeTrue() ? (Apple) new Granny() : (Apple) new Fuji();
Apple a = apple[0] = g;
assertEquals(g, a);
+
+ byte[] bytes = new byte[10];
+ bytes[0] = (byte) '1';
+ assertEquals(49, bytes[0]);
}
public void testCastOptimizer() {