[NI] Map vararg to Array if it's resolved against type variable
While this behavior is questionable, it's consistent with OI and can be changed in future #KT-36201 Fixed
This commit is contained in:
Generated
+10
@@ -1834,6 +1834,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVararg.kt")
|
||||
public void testGenericCallWithReferenceAgainstVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVarargAndKFunction.kt")
|
||||
public void testGenericCallWithReferenceAgainstVarargAndKFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt15439_completeCall.kt")
|
||||
public void testKt15439_completeCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.kt");
|
||||
|
||||
+5
-2
@@ -170,7 +170,8 @@ class CallableReferencesCandidateFactory(
|
||||
val callComponents: KotlinCallComponents,
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
|
||||
val expectedType: UnwrappedType?
|
||||
val expectedType: UnwrappedType?,
|
||||
private val csBuilder: ConstraintSystemOperation
|
||||
) : CandidateFactory<CallableReferenceCandidate> {
|
||||
|
||||
fun createCallableProcessor(explicitReceiver: DetailedReceiver?) =
|
||||
@@ -333,7 +334,9 @@ class CallableReferencesCandidateFactory(
|
||||
|
||||
return when (varargMappingState) {
|
||||
VarargMappingState.UNMAPPED -> {
|
||||
if (KotlinBuiltIns.isArrayOrPrimitiveArray(expectedParameterType)) {
|
||||
if (KotlinBuiltIns.isArrayOrPrimitiveArray(expectedParameterType) ||
|
||||
csBuilder.isTypeVariable(expectedParameterType)
|
||||
) {
|
||||
val arrayType = builtins.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(elementType)
|
||||
?: builtins.getArrayType(Variance.OUT_VARIANCE, elementType)
|
||||
arrayType to VarargMappingState.MAPPED_WITH_ARRAY
|
||||
|
||||
+5
-2
@@ -78,7 +78,7 @@ class CallableReferenceResolver(
|
||||
val expectedType = resolvedAtom.expectedType?.let { (csBuilder.buildCurrentSubstitutor() as NewTypeSubstitutor).safeSubstitute(it) }
|
||||
|
||||
val scopeTower = callComponents.statelessCallbacks.getScopeTowerForCallableReferenceArgument(argument)
|
||||
val candidates = runRHSResolution(scopeTower, argument, expectedType) { checkCallableReference ->
|
||||
val candidates = runRHSResolution(scopeTower, argument, expectedType, csBuilder) { checkCallableReference ->
|
||||
csBuilder.runTransaction { checkCallableReference(this); false }
|
||||
}
|
||||
|
||||
@@ -133,9 +133,12 @@ class CallableReferenceResolver(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
callableReference: CallableReferenceKotlinCallArgument,
|
||||
expectedType: UnwrappedType?, // this type can have not fixed type variable inside
|
||||
csBuilder: ConstraintSystemBuilder,
|
||||
compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be rolled back
|
||||
): Set<CallableReferenceCandidate> {
|
||||
val factory = CallableReferencesCandidateFactory(callableReference, callComponents, scopeTower, compatibilityChecker, expectedType)
|
||||
val factory = CallableReferencesCandidateFactory(
|
||||
callableReference, callComponents, scopeTower, compatibilityChecker, expectedType, csBuilder
|
||||
)
|
||||
val processor = createCallableReferenceProcessor(factory)
|
||||
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true, name = callableReference.rhsName)
|
||||
return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(
|
||||
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo(vararg ints: Int) {}
|
||||
fun test(i: IntArray) {
|
||||
myLet(i, ::foo)
|
||||
myLet(::foo)
|
||||
<!INAPPLICABLE_CANDIDATE!>myLet<!><Int>(::foo)
|
||||
myLet<IntArray>(::foo)
|
||||
<!INAPPLICABLE_CANDIDATE!>myLetExplicit1<!>(::foo)
|
||||
myLetExplicit2(::foo)
|
||||
}
|
||||
|
||||
fun <T> myLet(t: T, block: (T) -> Unit) {}
|
||||
fun <T> myLet(block: (T) -> Unit) {}
|
||||
fun myLetExplicit1(block: (Int) -> Unit) {}
|
||||
fun myLetExplicit2(block: (IntArray) -> Unit) {}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo(vararg ints: Int) {}
|
||||
fun test(i: IntArray) {
|
||||
myLet(i, ::foo)
|
||||
myLet(::foo)
|
||||
myLet<Int>(<!TYPE_MISMATCH!>::foo<!>)
|
||||
myLet<IntArray>(::foo)
|
||||
myLetExplicit1(::foo)
|
||||
myLetExplicit2(::foo)
|
||||
}
|
||||
|
||||
fun <T> myLet(t: T, block: (T) -> Unit) {}
|
||||
fun <T> myLet(block: (T) -> Unit) {}
|
||||
fun myLetExplicit1(block: (Int) -> Unit) {}
|
||||
fun myLetExplicit2(block: (IntArray) -> Unit) {}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ vararg ints: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit
|
||||
public fun </*0*/ T> myLet(/*0*/ block: (T) -> kotlin.Unit): kotlin.Unit
|
||||
public fun </*0*/ T> myLet(/*0*/ t: T, /*1*/ block: (T) -> kotlin.Unit): kotlin.Unit
|
||||
public fun myLetExplicit1(/*0*/ block: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||
public fun myLetExplicit2(/*0*/ block: (kotlin.IntArray) -> kotlin.Unit): kotlin.Unit
|
||||
public fun test(/*0*/ i: kotlin.IntArray): kotlin.Unit
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <A1> fun2(f: kotlin.reflect.KFunction1<A1, Unit>, a: A1) {
|
||||
f.invoke(a)
|
||||
}
|
||||
|
||||
fun containsRegex(vararg otherPatterns: String) {}
|
||||
|
||||
fun main() {
|
||||
fun2(::containsRegex, arrayOf("foo"))
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <A1> fun2(f: kotlin.reflect.KFunction1<A1, Unit>, a: A1) {
|
||||
f.invoke(a)
|
||||
}
|
||||
|
||||
fun containsRegex(vararg otherPatterns: String) {}
|
||||
|
||||
fun main() {
|
||||
fun2(::containsRegex, arrayOf("foo"))
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun containsRegex(/*0*/ vararg otherPatterns: kotlin.String /*kotlin.Array<out kotlin.String>*/): kotlin.Unit
|
||||
public fun </*0*/ A1> fun2(/*0*/ f: kotlin.reflect.KFunction1<A1, kotlin.Unit>, /*1*/ a: A1): kotlin.Unit
|
||||
public fun main(): kotlin.Unit
|
||||
@@ -1841,6 +1841,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVararg.kt")
|
||||
public void testGenericCallWithReferenceAgainstVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVarargAndKFunction.kt")
|
||||
public void testGenericCallWithReferenceAgainstVarargAndKFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt15439_completeCall.kt")
|
||||
public void testKt15439_completeCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.kt");
|
||||
|
||||
Generated
+10
@@ -1836,6 +1836,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVararg.kt")
|
||||
public void testGenericCallWithReferenceAgainstVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericCallWithReferenceAgainstVarargAndKFunction.kt")
|
||||
public void testGenericCallWithReferenceAgainstVarargAndKFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt15439_completeCall.kt")
|
||||
public void testKt15439_completeCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.kt");
|
||||
|
||||
Reference in New Issue
Block a user