Introduce language feature to enable the correct arguments execution order for named varargs (KT-17691)
This commit is contained in:
Generated
+10
@@ -355,6 +355,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
+28
-9
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
|
||||
@@ -227,7 +229,13 @@ class KotlinToResolvedCallTransformer(
|
||||
return storedResolvedCall
|
||||
}
|
||||
}
|
||||
return NewResolvedCallImpl(completedSimpleAtom, resultSubstitutor, diagnostics, typeApproximator)
|
||||
return NewResolvedCallImpl(
|
||||
completedSimpleAtom,
|
||||
resultSubstitutor,
|
||||
diagnostics,
|
||||
typeApproximator,
|
||||
expressionTypingServices.languageVersionSettings
|
||||
)
|
||||
}
|
||||
|
||||
fun runCallCheckers(resolvedCall: ResolvedCall<*>, callCheckerContext: CallCheckerContext) {
|
||||
@@ -551,6 +559,7 @@ class TrackingBindingTrace(val trace: BindingTrace) : BindingTrace by trace {
|
||||
sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D> {
|
||||
abstract val argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
|
||||
abstract val kotlinCall: KotlinCall
|
||||
protected abstract val languageVersionSettings: LanguageVersionSettings
|
||||
|
||||
protected var argumentToParameterMap: Map<ValueArgument, ArgumentMatchImpl>? = null
|
||||
protected var _valueArguments: Map<ValueParameterDescriptor, ResolvedValueArgument>? = null
|
||||
@@ -620,6 +629,8 @@ sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D>
|
||||
|
||||
private fun createValueArguments(): Map<ValueParameterDescriptor, ResolvedValueArgument> =
|
||||
LinkedHashMap<ValueParameterDescriptor, ResolvedValueArgument>().also { result ->
|
||||
val needToUseCorrectExecutionOrderForVarargArguments =
|
||||
languageVersionSettings.getFeatureSupport(LanguageFeature.UseCorrectExecutionOrderForVarargArguments) == LanguageFeature.State.ENABLED
|
||||
var varargMappings: MutableList<Pair<ValueParameterDescriptor, VarargValueArgument>>? = null
|
||||
for ((originalParameter, resolvedCallArgument) in argumentMappingByOriginal) {
|
||||
val resultingParameter = resultingDescriptor.valueParameters[originalParameter.index]
|
||||
@@ -630,12 +641,17 @@ sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D>
|
||||
is ResolvedCallArgument.SimpleArgument -> {
|
||||
val valueArgument = resolvedCallArgument.callArgument.psiCallArgument.valueArgument
|
||||
if (resultingParameter.isVararg) {
|
||||
val vararg = VarargValueArgument().apply { addArgument(valueArgument) }
|
||||
if (varargMappings == null) varargMappings = SmartList()
|
||||
varargMappings.add(resultingParameter to vararg)
|
||||
continue
|
||||
} else
|
||||
if (needToUseCorrectExecutionOrderForVarargArguments) {
|
||||
VarargValueArgument().apply { addArgument(valueArgument) }
|
||||
} else {
|
||||
val vararg = VarargValueArgument().apply { addArgument(valueArgument) }
|
||||
if (varargMappings == null) varargMappings = SmartList()
|
||||
varargMappings.add(resultingParameter to vararg)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
ExpressionValueArgument(valueArgument)
|
||||
}
|
||||
}
|
||||
is ResolvedCallArgument.VarargArgument ->
|
||||
VarargValueArgument().apply {
|
||||
@@ -644,9 +660,11 @@ sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D>
|
||||
}
|
||||
}
|
||||
|
||||
if (varargMappings != null) {
|
||||
for ((parameter, argument) in varargMappings) {
|
||||
result[parameter] = argument
|
||||
if (varargMappings != null && !needToUseCorrectExecutionOrderForVarargArguments) {
|
||||
if (varargMappings != null) {
|
||||
for ((parameter, argument) in varargMappings) {
|
||||
result[parameter] = argument
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -658,6 +676,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
substitutor: NewTypeSubstitutor?,
|
||||
private var diagnostics: Collection<KotlinCallDiagnostic>,
|
||||
private val typeApproximator: TypeApproximator,
|
||||
override val languageVersionSettings: LanguageVersionSettings,
|
||||
) : NewAbstractResolvedCall<D>() {
|
||||
var isCompleted = false
|
||||
private set
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// !LANGUAGE: -UseCorrectExecutionOrderForVarargArguments
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
fun foo(vararg x: Unit, y: Any) {}
|
||||
|
||||
fun box(): String {
|
||||
var acc1 = ""
|
||||
var acc2 = ""
|
||||
var acc3 = ""
|
||||
var acc4 = ""
|
||||
foo({ acc1 += "1" }(), y = { acc1 += "2" }())
|
||||
foo(x = *arrayOf({ acc2 += "1" }()), y = { acc2 += "2" }())
|
||||
foo(x = arrayOf({ acc3 += "1" }()), y = { acc3 += "2" }())
|
||||
foo(*arrayOf({ acc4 += "1" }()), y = { acc4 += "2" }())
|
||||
|
||||
return if (acc1 == "12" && acc2 == "21" && acc3 == "21" && acc4 == "12") "OK" else "ERROR"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +UseCorrectExecutionOrderForVarargArguments
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
fun foo(vararg x: Unit, y: Any) {}
|
||||
|
||||
fun box(): String {
|
||||
var acc1 = ""
|
||||
var acc2 = ""
|
||||
var acc3 = ""
|
||||
var acc4 = ""
|
||||
foo({ acc1 += "1" }(), y = { acc1 += "2" }())
|
||||
foo(x = *arrayOf({ acc2 += "1" }()), y = { acc2 += "2" }())
|
||||
foo(x = arrayOf({ acc3 += "1" }()), y = { acc3 += "2" }())
|
||||
foo(*arrayOf({ acc4 += "1" }()), y = { acc4 += "2" }())
|
||||
|
||||
return if (acc1 == "12" && acc2 == "12" && acc3 == "12" && acc4 == "12") "OK" else "ERROR"
|
||||
}
|
||||
+10
@@ -355,6 +355,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
+10
@@ -355,6 +355,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
@@ -140,6 +140,7 @@ enum class LanguageFeature(
|
||||
RequiredPrimaryConstructorDelegationCallInEnums(KOTLIN_1_5, kind = BUG_FIX),
|
||||
ForbidAnonymousReturnTypesInPrivateInlineFunctions(KOTLIN_1_5, kind = BUG_FIX),
|
||||
ForbidReferencingToUnderscoreNamedParameterOfCatchBlock(KOTLIN_1_5, kind = BUG_FIX),
|
||||
UseCorrectExecutionOrderForVarargArguments(KOTLIN_1_5, kind = BUG_FIX),
|
||||
|
||||
// Temporarily disabled, see KT-27084/KT-22379
|
||||
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
||||
|
||||
Generated
+10
@@ -140,6 +140,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
Generated
+10
@@ -140,6 +140,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
+10
@@ -140,6 +140,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/extensionInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691.kt")
|
||||
public void testKt17691() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17691WithEnabledFeature.kt")
|
||||
public void testKt17691WithEnabledFeature() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt17691WithEnabledFeature.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9277.kt")
|
||||
public void testKt9277() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/argumentOrder/kt9277.kt");
|
||||
|
||||
Reference in New Issue
Block a user