Test and fix for abstract var overriding.
This commit is contained in:
@@ -55,6 +55,10 @@ public final class ClassInheritanceTest extends TranslationTest {
|
|||||||
public void testDefinitionOrder() throws Exception {
|
public void testDefinitionOrder() throws Exception {
|
||||||
checkFooBoxIsTrue("definitionOrder.kt");
|
checkFooBoxIsTrue("definitionOrder.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAbstractVarOverride() throws Exception {
|
||||||
|
checkFooBoxIsTrue("abstractVarOverride.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
|||||||
import org.jetbrains.k2js.translate.utils.PredefinedAnnotation;
|
import org.jetbrains.k2js.translate.utils.PredefinedAnnotation;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.*;
|
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.*;
|
||||||
import static org.jetbrains.k2js.translate.utils.DescriptorUtils.*;
|
import static org.jetbrains.k2js.translate.utils.DescriptorUtils.*;
|
||||||
@@ -258,18 +257,14 @@ public final class StaticContext {
|
|||||||
@Override
|
@Override
|
||||||
public JsName apply(@NotNull DeclarationDescriptor descriptor) {
|
public JsName apply(@NotNull DeclarationDescriptor descriptor) {
|
||||||
//TODO: refactor
|
//TODO: refactor
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
if (!(descriptor instanceof FunctionDescriptor)) {
|
||||||
Set<? extends FunctionDescriptor> overriddenDescriptors = ((FunctionDescriptor) descriptor).getOverriddenDescriptors();
|
return null;
|
||||||
if (overriddenDescriptors.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//assert overriddenDescriptors.size() == 1;
|
|
||||||
//TODO: for now translator can't deal with multiple inheritance good enough
|
|
||||||
return getNameForDescriptor(overriddenDescriptors.iterator().next());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
FunctionDescriptor overriddenDescriptor = getOverriddenDescriptor((FunctionDescriptor) descriptor);
|
||||||
|
if (overriddenDescriptor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getNameForDescriptor(overriddenDescriptor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addRule(namesForStandardClasses);
|
addRule(namesForStandardClasses);
|
||||||
@@ -278,8 +273,8 @@ public final class StaticContext {
|
|||||||
addRule(toStringHack);
|
addRule(toStringHack);
|
||||||
addRule(propertiesCorrespondToSpeciallyTreatedBackingFieldNames);
|
addRule(propertiesCorrespondToSpeciallyTreatedBackingFieldNames);
|
||||||
addRule(namespacesShouldBeDefinedInRootScope);
|
addRule(namespacesShouldBeDefinedInRootScope);
|
||||||
addRule(accessorsHasNamesWithSpecialPrefixes);
|
|
||||||
addRule(overridingDescriptorsReferToOriginalName);
|
addRule(overridingDescriptorsReferToOriginalName);
|
||||||
|
addRule(accessorsHasNamesWithSpecialPrefixes);
|
||||||
addRule(memberDeclarationsInsideParentsScope);
|
addRule(memberDeclarationsInsideParentsScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,5 +219,27 @@ public final class DescriptorUtils {
|
|||||||
return classDescriptors;
|
return classDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static FunctionDescriptor getOverriddenDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
|
Set<? extends FunctionDescriptor> overriddenDescriptors = functionDescriptor.getOverriddenDescriptors();
|
||||||
|
if (overriddenDescriptors.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//TODO: for now translator can't deal with multiple inheritance good enough
|
||||||
|
return overriddenDescriptors.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO:?
|
||||||
|
// @NotNull
|
||||||
|
// public static FunctionDescriptor getOverriddenOrThis(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
|
// FunctionDescriptor overriddenDescriptor = getOverriddenDescriptor(functionDescriptor);
|
||||||
|
// if (overriddenDescriptor != null) {
|
||||||
|
// return overriddenDescriptor;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// return functionDescriptor;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
open abstract class A() {
|
||||||
|
abstract var pos : Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
class B() : A() {
|
||||||
|
override var pos : Int = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : Boolean {
|
||||||
|
|
||||||
|
val a : A = B()
|
||||||
|
if (a.pos != 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (B().pos != 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
a.pos = 3;
|
||||||
|
if (a.pos != 3) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user