[FIR] Display actual type for argument type mismatch error

Previously the argument type was being used for the actual type error
display. However, safe-call arguments are unwrapped which causes
nullable types to be displayed as non-null. Change to use the actual
type provided by the diagnostic instead of extracting the type from
the argument.

#KT-58844 Fixed
This commit is contained in:
Brian Norman
2023-06-15 08:25:22 -05:00
committed by Space Team
parent a7ff0cfc9d
commit 269dfc61c8
10 changed files with 57 additions and 3 deletions
@@ -22744,6 +22744,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/nullableTypes/inferenceFlexibleTToNullable.kt");
}
@Test
@TestMetadata("kt58844.kt")
public void testKt58844() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt");
}
@Test
@TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt")
public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {
@@ -22744,6 +22744,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/nullableTypes/inferenceFlexibleTToNullable.kt");
}
@Test
@TestMetadata("kt58844.kt")
public void testKt58844() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt");
}
@Test
@TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt")
public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {
@@ -22744,6 +22744,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/nullableTypes/inferenceFlexibleTToNullable.kt");
}
@Test
@TestMetadata("kt58844.kt")
public void testKt58844() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt");
}
@Test
@TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt")
public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {
@@ -22750,6 +22750,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/nullableTypes/inferenceFlexibleTToNullable.kt");
}
@Test
@TestMetadata("kt58844.kt")
public void testKt58844() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt");
}
@Test
@TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt")
public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {
@@ -223,7 +223,7 @@ private fun mapInapplicableCandidateError(
FirErrors.ARGUMENT_TYPE_MISMATCH.createOn(
rootCause.argument.source ?: source,
rootCause.expectedType.removeTypeVariableTypes(typeContext),
rootCause.argument.typeRef.coneType.removeTypeVariableTypes(typeContext),
rootCause.actualType.removeTypeVariableTypes(typeContext),
rootCause.isMismatchDueToNullability
)
}
@@ -11,7 +11,7 @@ compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:74: error: cannot a
compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:7:20: error: 'this' is not defined in this context
class B(other: B = this)
^
compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:10:32: error: argument type mismatch: actual type is kotlin/Function0<ERROR CLASS: Cannot access ''<this>'' before the instance has been initialized> but kotlin/Int was expected
compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:10:32: error: argument type mismatch: actual type is kotlin/Function0<ERROR CLASS: Unknown return lambda parameter type> but kotlin/Int was expected
constructor(x: Int) : this({
^
compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:12:9: error: cannot access '<this>' before the instance has been initialized
@@ -12,7 +12,7 @@ annotation class Ann
fun <@Ann R : @Ann Any> f3(a: Array<@Ann R>): Array<@Ann R?> = null!!
fun test2(a: @Ann Array<in @Ann Int>) {
val r: Array<in Int?> = f3(<!ARGUMENT_TYPE_MISMATCH("kotlin/Array<@R|Ann|() R>; @R|Ann|() kotlin/Array<in @R|Ann|() kotlin/Int>")!>a<!>)
val r: Array<in Int?> = f3(<!ARGUMENT_TYPE_MISMATCH("kotlin/Array<@R|Ann|() R>; @R|Ann|() kotlin/Array<CapturedType(in @R|Ann|() kotlin/Int)>")!>a<!>)
}
@@ -0,0 +1,12 @@
// !RENDER_DIAGNOSTICS_MESSAGES
fun intFun(i: Int) {}
fun byteFun(i: Byte) {}
fun main(args: Array<String>) {
var intVar: Int? = 1
var byteVar: Byte? = 1
intFun(<!ARGUMENT_TYPE_MISMATCH("kotlin/Int; kotlin/Int?")!>intVar?.toInt()<!>)
byteFun(<!ARGUMENT_TYPE_MISMATCH("kotlin/Byte; kotlin/Byte?")!>byteVar?.toByte()<!>)
}
@@ -0,0 +1,12 @@
// !RENDER_DIAGNOSTICS_MESSAGES
fun intFun(i: Int) {}
fun byteFun(i: Byte) {}
fun main(args: Array<String>) {
var intVar: Int? = 1
var byteVar: Byte? = 1
intFun(<!TYPE_MISMATCH!>intVar?.toInt()<!>)
byteFun(<!TYPE_MISMATCH!>byteVar?.toByte()<!>)
}
@@ -23570,6 +23570,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/nullableTypes/inferenceFlexibleTToNullable.kt");
}
@Test
@TestMetadata("kt58844.kt")
public void testKt58844() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt");
}
@Test
@TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt")
public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {