Stephen Haberman has uploaded a new change for review.
https://gwt-review.googlesource.com/3030
Change subject: Fix non-final field initializers running before the super
cstr.
......................................................................
Fix non-final field initializers running before the super cstr.
Previously, any field with an initializer would get assigned at
the top-level scope, before any cstrs had run.
However, this does not match the JVM behavior, which is that final fields
behave
this way, but non-field fields have their type's default value assigned when
super cstrs run, and then only later in their cstr are assigned to the
initializer.
Fixes #380.
Change-Id: I4c8ed0cd718a2188b33cc290fec6071c89be7918
---
M dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git
a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index c0e1423..7a93095 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -857,10 +857,13 @@
JsNameRef localRef = (JsNameRef) pop(); // localRef
JVariable target = x.getVariableRef().getTarget();
- if (target instanceof JField && ((JField)
target).getLiteralInitializer() != null) {
- // Will initialize at top scope; no need to double-initialize.
- push(null);
- return;
+ if (target instanceof JField) {
+ JField field = (JField) target;
+ if (field.isFinal() && field.getLiteralInitializer() != null) {
+ // Will initialize at top scope; no need to double-initialize.
+ push(null);
+ return;
+ }
}
JsBinaryOperation binOp =
@@ -891,8 +894,13 @@
public void endVisit(JField x, Context ctx) {
// if we need an initial value, create an assignment
if (x.getLiteralInitializer() != null) {
- // setup the constant value
- accept(x.getLiteralInitializer());
+ if (x.isFinal()) {
+ // setup the constant value
+ accept(x.getLiteralInitializer());
+ } else {
+ // setup the default value, see Issue 380
+ accept(x.getType().getDefaultValue());
+ }
} else if (!x.hasInitializer() && x.getEnclosingType() !=
program.getTypeJavaLangObject()) {
// setup a default value
accept(x.getType().getDefaultValue());
--
To view, visit https://gwt-review.googlesource.com/3030
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c8ed0cd718a2188b33cc290fec6071c89be7918
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Stephen Haberman <[email protected]>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.