[FE 1.0] Report progressions resolve changing warning while calling Java methods which pass Collection

^KT-51062 Fixed
This commit is contained in:
Victor Petukhov
2022-01-31 18:42:50 +03:00
parent 8f23fc54a4
commit a54c9edaad
9 changed files with 165 additions and 5 deletions
@@ -4594,6 +4594,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/checkArguments/kt49276Error.kt");
}
@Test
@TestMetadata("kt51062.kt")
public void testKt51062() throws Exception {
runTest("compiler/testData/diagnostics/tests/checkArguments/kt51062.kt");
}
@Test
@TestMetadata("overloadedFunction.kt")
public void testOverloadedFunction() throws Exception {
@@ -4594,6 +4594,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/checkArguments/kt49276Error.kt");
}
@Test
@TestMetadata("kt51062.kt")
public void testKt51062() throws Exception {
runTest("compiler/testData/diagnostics/tests/checkArguments/kt51062.kt");
}
@Test
@TestMetadata("overloadedFunction.kt")
public void testOverloadedFunction() throws Exception {
@@ -4594,6 +4594,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/checkArguments/kt49276Error.kt");
}
@Test
@TestMetadata("kt51062.kt")
public void testKt51062() throws Exception {
runTest("compiler/testData/diagnostics/tests/checkArguments/kt51062.kt");
}
@Test
@TestMetadata("overloadedFunction.kt")
public void testOverloadedFunction() throws Exception {
@@ -372,7 +372,7 @@ internal fun List<KotlinCallArgument>.replaceTypes(
internal fun PSIKotlinCall.replaceArguments(
newArguments: List<KotlinCallArgument>,
newReceiverArgument: ReceiverExpressionKotlinCallArgument? = null,
newReceiverArgument: ReceiverKotlinCallArgument? = null,
): PSIKotlinCall = PSIKotlinCallImpl(
callKind, psiCall, tracingStrategy, newReceiverArgument, dispatchReceiverForInvokeExtension, name, typeArguments, newArguments,
externalArgument, startingDataFlowInfo, resultDataFlowInfo, dataFlowInfoForArguments, isForImplicitInvoke
@@ -78,7 +78,7 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
)
)
}
val newCall = kotlinCall.replaceArguments(newArguments)
val newCall = kotlinCall.replaceArguments(newArguments, kotlinCall.explicitReceiver)
val candidateForCollectionReplacedArgument = kotlinCallResolver.resolveCall(
scopeTower, resolutionCallbacks, newCall, expectedType, context.collectAllCandidates
@@ -107,12 +107,12 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
} else type
} ?: continue
val cons = alternativeParameterType.constructor
val alternativeParameterTypeConstructor = alternativeParameterType.upperIfFlexible().constructor
if (cons.declarationDescriptor != builtIns.collection && (cons !is IntersectionTypeConstructor || cons.supertypes.none { it.constructor.declarationDescriptor == builtIns.collection })) continue
if (alternativeParameterTypeConstructor.declarationDescriptor != builtIns.collection && (alternativeParameterTypeConstructor !is IntersectionTypeConstructor || alternativeParameterTypeConstructor.supertypes.none { it.constructor.declarationDescriptor == builtIns.collection })) continue
val argumentExpression = argument.psiExpression ?: continue
val initialArgumentType = resolvedCall.candidateDescriptor.valueParameters.getOrNull(i)?.type ?: continue
val initialArgumentType = resolvedCall.candidateDescriptor.valueParameters.getOrNull(i)?.type?.upperIfFlexible() ?: continue
// Iterable initial type is an exception, considered as similar to Collection passing candidate
if (initialArgumentType.constructor.declarationDescriptor == builtIns.iterable) continue
@@ -0,0 +1,53 @@
// WITH_STDLIB
// FULL_JDK
// FILE: JavaSmartList.java
import kotlin.ranges.ClosedRange;
import java.util.Collection;
public class JavaSmartList <E> {
JavaSmartList(E x) {}
JavaSmartList(Collection<E> x) {}
static void append(Object x) {}
static void append(Collection<?> x) {}
static void append2(Iterable<?> x) {}
static void append2(Collection<?> x) {}
public static class In <T> {
In(T x) {}
}
static void append3(In<?> x) {}
static void append3(In<Collection<?>> x) {}
static <E> void append4(E x) {}
static <E extends Collection<?>> void append4(E x) {}
static <T> void takes(T x) {}
static <T extends Collection<?> & ClosedRange<?>> void takes(T x) {}
}
// FILE: main.kt
fun main() {
JavaSmartList(1..2) // warning
JavaSmartList<IntRange>(1..10) // no warning
JavaSmartList.append(1..10) // warning
JavaSmartList.append((1..10) as Any) // no warning
JavaSmartList.append((1..10) as Iterable<Int>) // no warning
JavaSmartList.append("a".."z") // no warning, the range is not iterable
JavaSmartList.append(1.0..2.0)
JavaSmartList.append2(1..10) // no warning
JavaSmartList.append3(JavaSmartList.In(1..10)) // no warning
JavaSmartList.append4(1..10) // warning
JavaSmartList.append4<IntRange>(1..10) // warning
JavaSmartList.takes(1..10) // warning
}
@@ -0,0 +1,53 @@
// WITH_STDLIB
// FULL_JDK
// FILE: JavaSmartList.java
import kotlin.ranges.ClosedRange;
import java.util.Collection;
public class JavaSmartList <E> {
JavaSmartList(E x) {}
JavaSmartList(Collection<E> x) {}
static void append(Object x) {}
static void append(Collection<?> x) {}
static void append2(Iterable<?> x) {}
static void append2(Collection<?> x) {}
public static class In <T> {
In(T x) {}
}
static void append3(In<?> x) {}
static void append3(In<Collection<?>> x) {}
static <E> void append4(E x) {}
static <E extends Collection<?>> void append4(E x) {}
static <T> void takes(T x) {}
static <T extends Collection<?> & ClosedRange<?>> void takes(T x) {}
}
// FILE: main.kt
fun main() {
JavaSmartList(<!PROGRESSIONS_CHANGING_RESOLVE_WARNING("constructor JavaSmartList<E : Any!>(x: (Mutable)Collection<E!>!)")!>1..2<!>) // warning
JavaSmartList<IntRange>(1..10) // no warning
JavaSmartList.append(<!PROGRESSIONS_CHANGING_RESOLVE_WARNING("fun append(x: (Mutable)Collection<*>!): Unit")!>1..10<!>) // warning
JavaSmartList.append((1..10) as Any) // no warning
JavaSmartList.append((1..10) as Iterable<Int>) // no warning
JavaSmartList.append("a".."z") // no warning, the range is not iterable
JavaSmartList.append(1.0..2.0)
JavaSmartList.append2(1..10) // no warning
JavaSmartList.append3(JavaSmartList.In(1..10)) // no warning
JavaSmartList.append4(<!PROGRESSIONS_CHANGING_RESOLVE_WARNING("fun <E : (Mutable)Collection<*>!> append4(x: E!): Unit")!>1..10<!>) // warning
JavaSmartList.append4<IntRange>(1..10) // warning
JavaSmartList.takes(<!PROGRESSIONS_CHANGING_RESOLVE_WARNING("fun <T : (Mutable)Collection<*>!> takes(x: T!): Unit where T : ClosedRange<*>!")!>1..10<!>) // warning
}
@@ -0,0 +1,30 @@
package
public fun main(): kotlin.Unit
public open class JavaSmartList</*0*/ E : kotlin.Any!> {
public/*package*/ constructor JavaSmartList</*0*/ E : kotlin.Any!>(/*0*/ x: E!)
public/*package*/ constructor JavaSmartList</*0*/ E : kotlin.Any!>(/*0*/ x: kotlin.collections.(Mutable)Collection<E!>!)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open class In</*0*/ T : kotlin.Any!> {
public/*package*/ constructor In</*0*/ T : kotlin.Any!>(/*0*/ x: T!)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
// Static members
public/*package*/ open fun append(/*0*/ x: kotlin.Any!): kotlin.Unit
public/*package*/ open fun append(/*0*/ x: kotlin.collections.(Mutable)Collection<*>!): kotlin.Unit
public/*package*/ open fun append2(/*0*/ x: kotlin.collections.(Mutable)Collection<*>!): kotlin.Unit
public/*package*/ open fun append2(/*0*/ x: kotlin.collections.(Mutable)Iterable<*>!): kotlin.Unit
public/*package*/ open fun append3(/*0*/ x: JavaSmartList.In<*>!): kotlin.Unit
public/*package*/ open fun append3(/*0*/ x: JavaSmartList.In<kotlin.collections.(Mutable)Collection<*>!>!): kotlin.Unit
public/*package*/ open fun </*0*/ E : kotlin.Any!> append4(/*0*/ x: E!): kotlin.Unit
public/*package*/ open fun </*0*/ E : kotlin.collections.(Mutable)Collection<*>!> append4(/*0*/ x: E!): kotlin.Unit
public/*package*/ open fun </*0*/ T : kotlin.Any!> takes(/*0*/ x: T!): kotlin.Unit
public/*package*/ open fun </*0*/ T : kotlin.collections.(Mutable)Collection<*>!> takes(/*0*/ x: T!): kotlin.Unit where T : kotlin.ranges.ClosedRange<*>!
}
@@ -4600,6 +4600,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/checkArguments/kt49276Error.kt");
}
@Test
@TestMetadata("kt51062.kt")
public void testKt51062() throws Exception {
runTest("compiler/testData/diagnostics/tests/checkArguments/kt51062.kt");
}
@Test
@TestMetadata("overloadedFunction.kt")
public void testOverloadedFunction() throws Exception {