From caaf2114bfe751438950a1dda3bac2b7ea349a9f Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 25 Jan 2018 21:53:28 +0300 Subject: [PATCH] Fix error when superclass has final String fields --- .../org/teavm/backend/javascript/runtime.js | 2 +- tests/src/test/java/org/teavm/vm/VMTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 4fcaabc1b..ac10b1443 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -441,7 +441,7 @@ function $rt_metadata(data) { m.supertypes = data[i + 3]; if (m.superclass) { m.supertypes.push(m.superclass); - cls.prototype = new m.superclass(); + cls.prototype = Object.create(m.superclass.prototype); } else { cls.prototype = {}; } diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index 72bbe6f4d..061781cfa 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -440,4 +440,17 @@ public class VMTest { a[0] = "bar"; assertEquals("foo", b[0]); } + + + @Test + public void stringConstantsInBaseClass() { + new DerivedClassWithConstantFields(); + } + + static class BaseClassWithConstantFields { + public final String foo = "bar"; + } + + static class DerivedClassWithConstantFields extends BaseClassWithConstantFields { + } } \ No newline at end of file