Remove uncapturing in type mismatch diagnostics
#KT-32587 Fixed
This commit is contained in:
+5
@@ -8341,6 +8341,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("captured.kt")
|
||||||
|
public void testCaptured() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/captured.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerLocalClass.kt")
|
@TestMetadata("innerLocalClass.kt")
|
||||||
public void testInnerLocalClass() throws Exception {
|
public void testInnerLocalClass() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
||||||
|
|||||||
+5
-5
@@ -257,7 +257,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
val index = parameterTypes.indexOf(constraintError.upperKotlinType.unwrap())
|
val index = parameterTypes.indexOf(constraintError.upperKotlinType.unwrap())
|
||||||
val lambdaExpression = lambda.psiExpression as? KtLambdaExpression ?: return@lambda
|
val lambdaExpression = lambda.psiExpression as? KtLambdaExpression ?: return@lambda
|
||||||
val parameter = lambdaExpression.valueParameters.getOrNull(index) ?: return@lambda
|
val parameter = lambdaExpression.valueParameters.getOrNull(index) ?: return@lambda
|
||||||
trace.report(Errors.EXPECTED_PARAMETER_TYPE_MISMATCH.on(parameter, constraintError.upperKotlinType.unCapture()))
|
trace.report(Errors.EXPECTED_PARAMETER_TYPE_MISMATCH.on(parameter, constraintError.upperKotlinType))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,8 +277,8 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
trace.report(
|
trace.report(
|
||||||
Errors.TYPE_MISMATCH.on(
|
Errors.TYPE_MISMATCH.on(
|
||||||
deparenthesized,
|
deparenthesized,
|
||||||
constraintError.upperKotlinType.unCapture(),
|
constraintError.upperKotlinType,
|
||||||
constraintError.lowerKotlinType.unCapture()
|
constraintError.lowerKotlinType
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -289,8 +289,8 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
trace.report(
|
trace.report(
|
||||||
Errors.TYPE_MISMATCH.on(
|
Errors.TYPE_MISMATCH.on(
|
||||||
it,
|
it,
|
||||||
constraintError.upperKotlinType.unCapture(),
|
constraintError.upperKotlinType,
|
||||||
constraintError.lowerKotlinType.unCapture()
|
constraintError.lowerKotlinType
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
class X {
|
||||||
|
abstract class Y<T : Any>
|
||||||
|
|
||||||
|
fun <T : Any> foo(y: Y<T>, t: T) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun testStar(y: X.Y<*>, t: Any) {
|
||||||
|
X().foo(y, <!TYPE_MISMATCH("CapturedType(*)", "Any")!>t<!>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testOut(y: X.Y<out Any>, t: Any) {
|
||||||
|
X().foo(y, <!TYPE_MISMATCH("CapturedType(out Any)", "Any")!>t<!>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testIn(y: X.Y<in Any>, t: Any) {
|
||||||
|
X().foo(y, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Any> testWithParameter(y: X.Y<T>, t: Any) {
|
||||||
|
X().foo(y, <!TYPE_MISMATCH("T", "Any")!>t<!>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Any> testWithCapturedParameter(y: X.Y<out T>, t: Any) {
|
||||||
|
X().foo(y, <!TYPE_MISMATCH("CapturedType(out T)", "Any")!>t<!>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun testIn(/*0*/ y: X.Y<in kotlin.Any>, /*1*/ t: kotlin.Any): kotlin.Unit
|
||||||
|
public fun testOut(/*0*/ y: X.Y<out kotlin.Any>, /*1*/ t: kotlin.Any): kotlin.Unit
|
||||||
|
public fun testStar(/*0*/ y: X.Y<*>, /*1*/ t: kotlin.Any): kotlin.Unit
|
||||||
|
public fun </*0*/ T : kotlin.Any> testWithCapturedParameter(/*0*/ y: X.Y<out T>, /*1*/ t: kotlin.Any): kotlin.Unit
|
||||||
|
public fun </*0*/ T : kotlin.Any> testWithParameter(/*0*/ y: X.Y<T>, /*1*/ t: kotlin.Any): kotlin.Unit
|
||||||
|
|
||||||
|
public final class X {
|
||||||
|
public constructor X()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun </*0*/ T : kotlin.Any> foo(/*0*/ y: X.Y<T>, /*1*/ t: T): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
public abstract class Y</*0*/ T : kotlin.Any> {
|
||||||
|
public constructor Y</*0*/ T : kotlin.Any>()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8348,6 +8348,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.*)\\.kts?$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.*)\\.kts?$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("captured.kt")
|
||||||
|
public void testCaptured() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/captured.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerLocalClass.kt")
|
@TestMetadata("innerLocalClass.kt")
|
||||||
public void testInnerLocalClass() throws Exception {
|
public void testInnerLocalClass() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
||||||
|
|||||||
Generated
+5
@@ -8343,6 +8343,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/capturedParameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("captured.kt")
|
||||||
|
public void testCaptured() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/captured.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerLocalClass.kt")
|
@TestMetadata("innerLocalClass.kt")
|
||||||
public void testInnerLocalClass() throws Exception {
|
public void testInnerLocalClass() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user