KT-2752: fix translation of call to internal function from subclass

This commit is contained in:
Alexey Andreev
2016-10-07 15:31:28 +03:00
parent c814a9d1d2
commit 322f6fe7ac
4 changed files with 33 additions and 3 deletions
@@ -126,7 +126,17 @@ class NameSuggestion {
// the class's parent scope.
//
val parts = mutableListOf<String>()
// For some strange reason we get FAKE_OVERRIDE for final functions called via subtype's receiver
var current: DeclarationDescriptor = descriptor
if (current is CallableMemberDescriptor && current.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
val overridden = getOverridden(current) as CallableMemberDescriptor
if (!overridden.isOverridableOrOverrides) {
current = overridden
}
}
val fixedDescriptor = current
do {
parts += getSuggestedName(current)
var last = current
@@ -146,8 +156,8 @@ class NameSuggestion {
parts.reverse()
val unmangledName = parts.joinToString("$")
val (id, stable) = mangleNameIfNecessary(unmangledName, descriptor)
return SuggestedName(listOf(id), stable, descriptor, current)
val (id, stable) = mangleNameIfNecessary(unmangledName, fixedDescriptor)
return SuggestedName(listOf(id), stable, fixedDescriptor, current)
}
// For regular names suggest its string representation
@@ -187,6 +197,10 @@ class NameSuggestion {
return mangleRegularNameIfNecessary(baseName, overriddenDescriptor)
}
private fun getOverridden(descriptor: CallableDescriptor): CallableDescriptor {
return generateSequence(descriptor) { it.overriddenDescriptors.firstOrNull()?.original }.last()
}
private fun mangleRegularNameIfNecessary(baseName: String, descriptor: DeclarationDescriptor): NameAndStability {
if (descriptor is ClassOrPackageFragmentDescriptor) {
return NameAndStability(baseName, !DescriptorUtils.isDescriptorWithLocalVisibility(descriptor))
@@ -213,6 +227,8 @@ class NameSuggestion {
// Make all public declarations stable
if (descriptor.visibility == Visibilities.PUBLIC) return mangledAndStable()
if (descriptor is CallableMemberDescriptor && descriptor.isOverridableOrOverrides) return mangledAndStable()
// Make all protected declarations of non-final public classes stable
if (descriptor.visibility == Visibilities.PROTECTED &&
!containingDeclaration.isFinalClass &&
@@ -2439,6 +2439,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("internalFunctionFromSuperclass.kt")
public void testInternalFunctionFromSuperclass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/invoke/internalFunctionFromSuperclass.kt");
doTest(fileName);
}
@TestMetadata("invokeInExtensionFunctionLiteral.kt")
public void testInvokeInExtensionFunctionLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/invoke/invokeInExtensionFunctionLiteral.kt");
@@ -298,7 +298,6 @@ public final class StaticContext {
List<JsName> names = new ArrayList<JsName>();
if (suggested.getStable()) {
for (String namePart : suggested.getNames()) {
names.add(scope.declareName(namePart));
}
@@ -0,0 +1,9 @@
abstract class A {
final internal fun foo() = "OK"
}
class B : A() {
fun bar() = foo()
}
fun box() = B().bar()