[FIR] Type argument instead of unexpected type parameter for TypeMismatch error
^KT-49035 ^KT-51201 Fixed
This commit is contained in:
+6
@@ -31508,6 +31508,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/starProjectionInsteadOutCaptured.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt")
|
||||
public void testTypeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("upperBoundCannotBeArray.kt")
|
||||
public void testUpperBoundCannotBeArray() throws Exception {
|
||||
|
||||
+6
@@ -31508,6 +31508,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/starProjectionInsteadOutCaptured.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt")
|
||||
public void testTypeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("upperBoundCannotBeArray.kt")
|
||||
public void testUpperBoundCannotBeArray() throws Exception {
|
||||
|
||||
+6
@@ -31508,6 +31508,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/starProjectionInsteadOutCaptured.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt")
|
||||
public void testTypeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("upperBoundCannotBeArray.kt")
|
||||
public void testUpperBoundCannotBeArray() throws Exception {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.VariableFixationFinder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
@@ -363,8 +364,16 @@ private fun checkApplicabilityForArgumentType(
|
||||
|
||||
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType {
|
||||
if (type is ConeTypeVariableType) {
|
||||
val lookupTag = type.lookupTag
|
||||
|
||||
val constraints = (csBuilder as VariableFixationFinder.Context).notFixedTypeVariables[lookupTag]?.constraints
|
||||
val constraintTypes = constraints?.mapNotNull { it.type as? ConeKotlinType }
|
||||
if (constraintTypes != null && constraintTypes.isNotEmpty()) {
|
||||
return ConeTypeIntersector.intersectTypes(context.session.typeContext, constraintTypes)
|
||||
}
|
||||
|
||||
val originalTypeParameter =
|
||||
(type.lookupTag as? ConeTypeVariableTypeConstructor)?.originalTypeParameter as? ConeTypeParameterLookupTag
|
||||
(lookupTag as? ConeTypeVariableTypeConstructor)?.originalTypeParameter as? ConeTypeParameterLookupTag
|
||||
|
||||
if (originalTypeParameter != null)
|
||||
return ConeTypeParameterTypeImpl(originalTypeParameter, type.isNullable, type.attributes)
|
||||
@@ -375,7 +384,6 @@ private fun checkApplicabilityForArgumentType(
|
||||
return type
|
||||
}
|
||||
|
||||
|
||||
return ArgumentTypeMismatch(
|
||||
tryGetConeTypeThatCompatibleWithKtType(actualExpectedType),
|
||||
tryGetConeTypeThatCompatibleWithKtType(argumentType),
|
||||
|
||||
@@ -445,11 +445,10 @@ internal object CheckArguments : CheckerStage() {
|
||||
val argumentMapping =
|
||||
candidate.argumentMapping ?: error("Argument should be already mapped while checking arguments!")
|
||||
for (argument in callInfo.arguments) {
|
||||
val parameter = argumentMapping[argument]
|
||||
candidate.resolveArgument(
|
||||
callInfo,
|
||||
argument,
|
||||
parameter,
|
||||
argumentMapping[argument],
|
||||
isReceiver = false,
|
||||
sink = sink,
|
||||
context = context
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// ISSUE: KT-49035, KT-51201
|
||||
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
fun <T> foo(it: @kotlin.internal.Exact T) {}
|
||||
|
||||
fun main() {
|
||||
foo<Any>(<!ARGUMENT_TYPE_MISMATCH("kotlin/Any; kotlin/String")!>""<!>)
|
||||
}
|
||||
|
||||
interface I
|
||||
class Foo : I
|
||||
class Bar
|
||||
|
||||
fun <MY_TYPE_PARAM : I> myRun(action: () -> MY_TYPE_PARAM): MY_TYPE_PARAM = action()
|
||||
|
||||
val a = myRun<Foo> { <!ARGUMENT_TYPE_MISMATCH("Foo; Bar")!>Bar()<!> }
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// ISSUE: KT-49035, KT-51201
|
||||
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
fun <T> foo(it: @kotlin.internal.Exact T) {}
|
||||
|
||||
fun main() {
|
||||
foo<Any>(<!TYPE_MISMATCH("String; Any")!>""<!>)
|
||||
}
|
||||
|
||||
interface I
|
||||
class Foo : I
|
||||
class Bar
|
||||
|
||||
fun <MY_TYPE_PARAM : I> myRun(action: () -> MY_TYPE_PARAM): MY_TYPE_PARAM = action()
|
||||
|
||||
val a = myRun<Foo> { <!TYPE_MISMATCH("Foo; Bar"), TYPE_MISMATCH("I; Bar")!>Bar()<!> }
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
public val a: Foo
|
||||
public fun </*0*/ T> foo(/*0*/ it: T): kotlin.Unit
|
||||
public fun main(): kotlin.Unit
|
||||
public fun </*0*/ MY_TYPE_PARAM : I> myRun(/*0*/ action: () -> MY_TYPE_PARAM): MY_TYPE_PARAM
|
||||
|
||||
public final class Bar {
|
||||
public constructor Bar()
|
||||
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 final class Foo : I {
|
||||
public constructor Foo()
|
||||
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 I {
|
||||
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
|
||||
}
|
||||
|
||||
Generated
+6
@@ -31598,6 +31598,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/starProjectionInsteadOutCaptured.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt")
|
||||
public void testTypeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("upperBoundCannotBeArray.kt")
|
||||
public void testUpperBoundCannotBeArray() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user