JS: fix translation of calls with aliased labeled lambda arguments. Fix KT-14999
This commit is contained in:
committed by
Alexey Andreev
parent
a6fb61f5c3
commit
784fe31053
@@ -0,0 +1,16 @@
|
||||
// See KT-14999
|
||||
|
||||
object Obj {
|
||||
var key = ""
|
||||
var value = ""
|
||||
|
||||
operator fun set(k: String, v: ((String) -> Unit) -> Unit) {
|
||||
key += k
|
||||
v { value += it }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Obj["O"] = label@{ it("K") }
|
||||
return Obj.key + Obj.value
|
||||
}
|
||||
+6
@@ -10307,6 +10307,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("operatorSetLambda.kt")
|
||||
public void testOperatorSetLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/operatorSetLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedSet.kt")
|
||||
public void testOverloadedSet() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/overloadedSet.kt");
|
||||
|
||||
@@ -10307,6 +10307,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("operatorSetLambda.kt")
|
||||
public void testOperatorSetLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/operatorSetLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedSet.kt")
|
||||
public void testOverloadedSet() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/overloadedSet.kt");
|
||||
|
||||
@@ -12546,6 +12546,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("operatorSetLambda.kt")
|
||||
public void testOperatorSetLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/operatorSetLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedSet.kt")
|
||||
public void testOverloadedSet() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/overloadedSet.kt");
|
||||
|
||||
+1
-7
@@ -26,7 +26,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.declaration.ClassTranslator;
|
||||
@@ -46,7 +45,6 @@ import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
@@ -54,13 +52,9 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.context.Namer.GET_KCLASS;
|
||||
import static org.jetbrains.kotlin.js.translate.context.Namer.GET_KCLASS_FROM_EXPRESSION;
|
||||
import static org.jetbrains.kotlin.js.translate.context.Namer.getCapturedVarAccessor;
|
||||
import static org.jetbrains.kotlin.js.translate.context.Namer.*;
|
||||
import static org.jetbrains.kotlin.js.translate.general.Translation.translateAsExpression;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.*;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.ErrorReportingUtils.message;
|
||||
|
||||
@@ -104,6 +104,15 @@ public final class Translation {
|
||||
return aliasForExpression;
|
||||
}
|
||||
|
||||
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
|
||||
if (compileTimeValue != null) {
|
||||
KotlinType type = context.bindingContext().getType(expression);
|
||||
if (type != null && KotlinBuiltIns.isLong(type)) {
|
||||
JsExpression constantResult = translateConstant(compileTimeValue, expression, context);
|
||||
if (constantResult != null) return constantResult;
|
||||
}
|
||||
}
|
||||
|
||||
TranslationContext innerContext = context.innerBlock();
|
||||
JsNode result = doTranslateExpression(expression, innerContext);
|
||||
context.moveVarsFrom(innerContext);
|
||||
@@ -175,15 +184,6 @@ public final class Translation {
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JsBlock block
|
||||
) {
|
||||
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
|
||||
if (compileTimeValue != null) {
|
||||
KotlinType type = context.bindingContext().getType(expression);
|
||||
if (type != null && KotlinBuiltIns.isLong(type)) {
|
||||
JsExpression constantResult = translateConstant(compileTimeValue, expression, context);
|
||||
if (constantResult != null) return constantResult;
|
||||
}
|
||||
}
|
||||
|
||||
JsNode jsNode = translateExpression(expression, context, block);
|
||||
if (jsNode instanceof JsExpression) {
|
||||
return (JsExpression) jsNode;
|
||||
|
||||
+4
-3
@@ -207,7 +207,8 @@ class CallArgumentTranslator private constructor(
|
||||
assert(actualArgument is ExpressionValueArgument)
|
||||
assert(valueArguments.size == 1)
|
||||
|
||||
val argumentExpression = KtPsiUtil.deparenthesize(valueArguments[0].getArgumentExpression())!!
|
||||
val parenthesizedArgumentExpression = valueArguments[0].getArgumentExpression()!!
|
||||
val argumentExpression = KtPsiUtil.deparenthesize(parenthesizedArgumentExpression)
|
||||
|
||||
result += if (parameterDescriptor.isCoroutine && argumentExpression is KtLambdaExpression) {
|
||||
val continuationType = parameterDescriptor.type.arguments.last().type
|
||||
@@ -218,7 +219,7 @@ class CallArgumentTranslator private constructor(
|
||||
argumentExpression.functionLiteral, continuationDescriptor, controllerDescriptor)
|
||||
}
|
||||
else {
|
||||
Translation.translateAsExpression(argumentExpression, context)
|
||||
Translation.translateAsExpression(parenthesizedArgumentExpression, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +331,7 @@ class CallArgumentTranslator private constructor(
|
||||
|
||||
}
|
||||
|
||||
public fun Map<TypeParameterDescriptor, KotlinType>.buildReifiedTypeArgs(
|
||||
fun Map<TypeParameterDescriptor, KotlinType>.buildReifiedTypeArgs(
|
||||
context: TranslationContext
|
||||
): List<JsExpression> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user