JS backend: fix init val in constructor
This commit is contained in:
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.JsTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -80,15 +79,19 @@ public final class PropertyAccessTest extends SingleFileTranslationTest {
|
||||
}
|
||||
|
||||
public void testInitInstanceProperties() throws Exception {
|
||||
fooBoxTest(JsTestUtils.successOnEcmaV5());
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testInitValInConstructor() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testEnumerable() throws Exception {
|
||||
fooBoxTest(JsTestUtils.successOnEcmaV5());
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testOverloadedOverriddenFunctionPropertyName() throws Exception {
|
||||
fooBoxTest(JsTestUtils.successOnEcmaV5());
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-1
@@ -28,6 +28,8 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.assignmentToBackingField;
|
||||
|
||||
/**
|
||||
* For properies /w accessors.
|
||||
*/
|
||||
@@ -78,7 +80,11 @@ public final class KotlinPropertyAccessTranslator extends PropertyAccessTranslat
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression translateAsSet(@NotNull JsExpression toSetTo) {
|
||||
return translateAsSet(receiver, toSetTo);
|
||||
if (propertyDescriptor.isVar()) {
|
||||
return translateAsSet(receiver, toSetTo);
|
||||
} else {
|
||||
return assignmentToBackingField(context(), propertyDescriptor, toSetTo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val a: Int
|
||||
val aa: Int
|
||||
get() {
|
||||
return $aa
|
||||
}
|
||||
|
||||
var aR = 0
|
||||
var aaR = 0
|
||||
{
|
||||
a = 1
|
||||
$aa = 2
|
||||
|
||||
aR = a
|
||||
aaR = aa
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
private val a: Int
|
||||
private val aa: Int
|
||||
get() {
|
||||
return $aa
|
||||
}
|
||||
|
||||
var aR = 0
|
||||
var aaR = 0
|
||||
{
|
||||
a = 3
|
||||
$aa = 4
|
||||
|
||||
aR = a
|
||||
aaR = aa
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.a != 1) return "a.a != 1, it: ${a.a}"
|
||||
if (a.aa != 2) return "a.aa != 2, it: ${a.aa}"
|
||||
if (a.aR != 1) return "a.aR != 1, it: ${a.aR}"
|
||||
if (a.aaR != 2) return "a.aaR != 2, it: ${a.aaR}"
|
||||
|
||||
val b = B()
|
||||
if (b.aR != 3) return "b.aR != 3, it: ${b.aR}"
|
||||
if (b.aaR != 4) return "b.aaR != 4, it: ${b.aaR}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user