JS backend: use FqNameUnsafe when generate delegateName to avoid problems with special names.
#EA-64029 Fixed
This commit is contained in:
@@ -95,4 +95,8 @@ public class DelegationTest extends SingleFileTranslationTest {
|
|||||||
public void testDelegationExtensionPropertyDelegated() throws Exception {
|
public void testDelegationExtensionPropertyDelegated() throws Exception {
|
||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOnObject() throws Exception {
|
||||||
|
checkFooBoxIsOk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-9
@@ -18,22 +18,25 @@ package org.jetbrains.kotlin.js.translate.declaration
|
|||||||
|
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
|
import org.jetbrains.kotlin.backend.common.CodegenUtil
|
||||||
|
import org.jetbrains.kotlin.backend.common.CodegenUtilKt
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.psi.*
|
|
||||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||||
|
import org.jetbrains.kotlin.js.translate.declaration.propertyTranslator.addGetterAndSetter
|
||||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator
|
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator
|
||||||
import org.jetbrains.kotlin.js.translate.general.Translation
|
import org.jetbrains.kotlin.js.translate.general.Translation
|
||||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils
|
import org.jetbrains.kotlin.js.translate.utils.BindingUtils
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.*
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|
||||||
import org.jetbrains.kotlin.backend.common.CodegenUtil
|
|
||||||
import java.util.HashMap
|
|
||||||
import org.jetbrains.kotlin.js.translate.declaration.propertyTranslator.addGetterAndSetter
|
|
||||||
import org.jetbrains.kotlin.js.translate.utils.ManglingUtils.getMangledMemberNameForExplicitDelegation
|
import org.jetbrains.kotlin.js.translate.utils.ManglingUtils.getMangledMemberNameForExplicitDelegation
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.translateFunctionAsEcma5PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.js.translate.utils.generateDelegateCall
|
import org.jetbrains.kotlin.js.translate.utils.generateDelegateCall
|
||||||
import org.jetbrains.kotlin.backend.common.CodegenUtilKt
|
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.JetDelegationSpecifier
|
||||||
|
import org.jetbrains.kotlin.psi.JetDelegatorByExpressionSpecifier
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
import java.util.HashMap
|
||||||
|
|
||||||
public class DelegationTranslator(
|
public class DelegationTranslator(
|
||||||
private val classDeclaration: JetClassOrObject,
|
private val classDeclaration: JetClassOrObject,
|
||||||
@@ -60,8 +63,9 @@ public class DelegationTranslator(
|
|||||||
fields.put(specifier, Field(propertyDescriptor!!.getName().asString(), false))
|
fields.put(specifier, Field(propertyDescriptor!!.getName().asString(), false))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val typeFqName = DescriptorUtils.getFqNameSafe(descriptor)
|
val classFqName = DescriptorUtils.getFqName(classDescriptor)
|
||||||
val delegateName = getMangledMemberNameForExplicitDelegation(Namer.getDelegatePrefix(), classDeclaration.getFqName(), typeFqName)
|
val typeFqName = DescriptorUtils.getFqName(descriptor)
|
||||||
|
val delegateName = getMangledMemberNameForExplicitDelegation(Namer.getDelegatePrefix(), classFqName, typeFqName)
|
||||||
fields.put(specifier, Field(delegateName, true))
|
fields.put(specifier, Field(delegateName, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import com.intellij.util.containers.ContainerUtil;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||||
@@ -113,7 +113,11 @@ public class ManglingUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getMangledMemberNameForExplicitDelegation(@NotNull String suggestedName, FqName classFqName, FqName typeFqName) {
|
public static String getMangledMemberNameForExplicitDelegation(
|
||||||
|
@NotNull String suggestedName,
|
||||||
|
@NotNull FqNameUnsafe classFqName,
|
||||||
|
@NotNull FqNameUnsafe typeFqName
|
||||||
|
) {
|
||||||
String forCalculateId = classFqName.asString() + ":" + typeFqName.asString();
|
String forCalculateId = classFqName.asString() + ":" + typeFqName.asString();
|
||||||
return getStableMangledName(suggestedName, forCalculateId);
|
return getStableMangledName(suggestedName, forCalculateId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
trait T {
|
||||||
|
fun foo(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
class TImpl(val v: String) : T {
|
||||||
|
override fun foo() = v
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object : T by TImpl("A.Default")
|
||||||
|
}
|
||||||
|
|
||||||
|
object B : T by TImpl("B")
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals("A.Default", A.foo())
|
||||||
|
assertEquals("B", B.foo())
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user