JS: fix Long inlining (private, companion) (KT-24189 fixed).
This commit is contained in:
+6
-2
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.UtilsKt;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -872,9 +873,12 @@ public class TranslationContext {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression declareConstantValue(@NotNull DeclarationDescriptor descriptor, @NotNull JsExpression value) {
|
||||
public JsExpression declareConstantValue(
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull JsExpression value) {
|
||||
if (!isPublicInlineFunction() && isFromCurrentModule(descriptor)) {
|
||||
return getQualifiedReference(descriptor);
|
||||
return ReferenceTranslator.translateSimpleName(expression, this);
|
||||
}
|
||||
|
||||
// Tag shouldn't be null if we cannot reference this descriptor locally.
|
||||
|
||||
@@ -102,12 +102,12 @@ public final class Translation {
|
||||
constantResult.setSource(expression);
|
||||
|
||||
if (KotlinBuiltIns.isLong(type)) {
|
||||
KtReferenceExpression referenceExpression = PsiUtils.getSimpleName(expression);
|
||||
KtSimpleNameExpression referenceExpression = PsiUtils.getSimpleName(expression);
|
||||
if (referenceExpression != null) {
|
||||
DeclarationDescriptor descriptor =
|
||||
BindingUtils.getDescriptorForReferenceExpression(context.bindingContext(), referenceExpression);
|
||||
if (descriptor != null) {
|
||||
return context.declareConstantValue(descriptor, constantResult);
|
||||
return context.declareConstantValue(descriptor, referenceExpression, constantResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,25 @@ fun testLongVal() {
|
||||
assertEquals(46L, twiceLongValue)
|
||||
}
|
||||
|
||||
private const val privateLongConst = 10 * 10L
|
||||
|
||||
internal const val internalLongConst = 10 * 100L
|
||||
|
||||
const val longConst = 42L
|
||||
|
||||
// PROPERTY_READ_COUNT: name=privateLongConst count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=L100 count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=internalLongConst count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=L1000 count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=longConst count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=L42 count=1 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=L_42 count=4 scope=testLongConst
|
||||
// PROPERTY_READ_COUNT: name=L84 count=2 scope=testLongConst
|
||||
fun testLongConst() {
|
||||
assertEquals(100L, privateLongConst)
|
||||
|
||||
assertEquals(1000L, internalLongConst)
|
||||
|
||||
val longConstCopy = longConst
|
||||
assertEquals(42L, longConstCopy)
|
||||
|
||||
@@ -144,6 +156,23 @@ private fun testImportedLongConstInlinedLocally() {
|
||||
testImportedLongConstInlineFunLib1()
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
private const val a = 10L
|
||||
|
||||
const val b = 20L
|
||||
}
|
||||
|
||||
fun testCompanion() {
|
||||
assertEquals(10L, a)
|
||||
assertEquals(20L, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun testCompanionVal() {
|
||||
A().testCompanion()
|
||||
}
|
||||
|
||||
fun testLib1() {
|
||||
testLongVal()
|
||||
testLongConst()
|
||||
@@ -154,6 +183,8 @@ fun testLib1() {
|
||||
testIntMaxMinValue()
|
||||
|
||||
testImportedLongConstInlinedLocally()
|
||||
|
||||
testCompanionVal()
|
||||
}
|
||||
|
||||
// MODULE: lib2(lib1)
|
||||
@@ -230,6 +261,8 @@ fun testLib2() {
|
||||
|
||||
testImportedLongConst()
|
||||
testImportedLongConstInlinedLocallyFromOtherModule()
|
||||
|
||||
assertEquals(20L, A.b)
|
||||
}
|
||||
|
||||
// MODULE: main(lib2)
|
||||
|
||||
Reference in New Issue
Block a user