[FIR] Fixed Replace ConeTypeVariable on ConeTypeParameter ^KT-51017

in AbstractConeCallConflictResolver.computeParameterTypes
This commit is contained in:
Ivan Kochurkin
2022-01-28 22:48:52 +03:00
committed by teamcity
parent 5391ee91af
commit a0510f4a67
9 changed files with 81 additions and 13 deletions
@@ -2646,6 +2646,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceWithMostSpecificGenericTypeParameter.kt");
}
@Test
@TestMetadata("classVsPackage.kt")
public void testClassVsPackage() throws Exception {
@@ -2646,6 +2646,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceWithMostSpecificGenericTypeParameter.kt");
}
@Test
@TestMetadata("classVsPackage.kt")
public void testClassVsPackage() throws Exception {
@@ -2646,6 +2646,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceWithMostSpecificGenericTypeParameter.kt");
}
@Test
@TestMetadata("classVsPackage.kt")
public void testClassVsPackage() throws Exception {
@@ -7,12 +7,17 @@ package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.resolve.calls.results.*
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.requireOrDescribe
import org.jetbrains.kotlin.utils.addIfNotNull
abstract class AbstractConeCallConflictResolver(
private val specificityComparator: TypeSpecificityComparator,
@@ -160,9 +165,28 @@ abstract class AbstractConeCallConflictResolver(
call: Candidate,
function: FirFunction
): List<ConeKotlinType> {
return listOfNotNull(function.receiverTypeRef?.coneType) +
(call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType }
?: call.argumentMapping?.map { it.value.argumentType() }.orEmpty())
return buildList {
addIfNotNull(function.receiverTypeRef?.coneType)
val typeForCallableReference = call.resultingTypeForCallableReference
if (typeForCallableReference != null) {
typeForCallableReference.typeArguments
.mapTo(this) {
when (it) {
is ConeTypeVariableType -> {
val typeParameterLookupTag = it.lookupTag.originalTypeParameter as ConeTypeParameterLookupTag?
if (typeParameterLookupTag == null) {
ConeErrorType(ConeSimpleDiagnostic("no type parameter for type variable", DiagnosticKind.Other))
} else {
ConeTypeParameterTypeImpl(typeParameterLookupTag, it.isNullable)
}
}
else -> it as ConeKotlinType
}
}
} else {
call.argumentMapping?.mapTo(this) { it.value.argumentType() }
}
}
}
private fun createFlatSignature(call: Candidate, klass: FirClassLikeDeclaration): FlatSignature<Candidate> {
@@ -0,0 +1,12 @@
// FIR_IDENTICAL
// ISSUE: KT-51017
interface A
interface B : A
fun <V : A> V.foo(): V = this
fun <T : B> T.foo(): T = this
fun test(list: List<B>) {
B::foo // No ambiguity, T.foo wins
}
@@ -0,0 +1,17 @@
package
public fun test(/*0*/ list: kotlin.collections.List<B>): kotlin.Unit
public fun </*0*/ T : B> T.foo(): T
public fun </*0*/ V : A> V.foo(): V
public interface A {
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 interface B : A {
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
}
@@ -1,10 +0,0 @@
// KT-11075 NONE_APPLICABLE reported for callable reference to an overloaded generic function with expected type provided
object TestCallableReferences {
fun <A> foo(x: A) = x
fun <B> foo(x: List<B>) = x
fun test0(): (String) -> String = TestCallableReferences::foo
fun <T> test1(): (List<T>) -> List<T> = TestCallableReferences::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// KT-11075 NONE_APPLICABLE reported for callable reference to an overloaded generic function with expected type provided
object TestCallableReferences {
@@ -2652,6 +2652,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceWithMostSpecificGenericTypeParameter.kt");
}
@Test
@TestMetadata("classVsPackage.kt")
public void testClassVsPackage() throws Exception {