NI: Report incompatible receiver of callable reference
^KT-35535 Fixed
This commit is contained in:
Generated
+5
@@ -1789,6 +1789,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("constraintFromLHSWithCorrectDirectionError.kt")
|
||||||
|
public void testConstraintFromLHSWithCorrectDirectionError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
||||||
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||||
|
|||||||
+7
-2
@@ -265,8 +265,13 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
NewConstraintError::class.java -> {
|
NewConstraintError::class.java -> {
|
||||||
val constraintError = diagnostic as NewConstraintError
|
val constraintError = diagnostic as NewConstraintError
|
||||||
val position = constraintError.position.from
|
val position = constraintError.position.from
|
||||||
val argument = (position as? ArgumentConstraintPosition)?.argument
|
val argument =
|
||||||
?: (position as? ReceiverConstraintPosition)?.argument
|
when (position) {
|
||||||
|
is ArgumentConstraintPosition -> position.argument
|
||||||
|
is ReceiverConstraintPosition -> position.argument
|
||||||
|
is LHSArgumentConstraintPosition -> position.argument
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
argument?.let {
|
argument?.let {
|
||||||
it.safeAs<LambdaKotlinCallArgument>()?.let lambda@{ lambda ->
|
it.safeAs<LambdaKotlinCallArgument>()?.let lambda@{ lambda ->
|
||||||
val parameterTypes = lambda.parametersTypes?.toList() ?: return@lambda
|
val parameterTypes = lambda.parametersTypes?.toList() ?: return@lambda
|
||||||
|
|||||||
+7
-3
@@ -162,7 +162,7 @@ private fun preprocessCallableReference(
|
|||||||
|
|
||||||
val lhsResult = argument.lhsResult
|
val lhsResult = argument.lhsResult
|
||||||
if (lhsResult is LHSResult.Type) {
|
if (lhsResult is LHSResult.Type) {
|
||||||
csBuilder.addConstraintFromLHS(lhsResult, expectedType)
|
csBuilder.addConstraintFromLHS(argument, lhsResult, expectedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
val notCallableTypeConstructor =
|
val notCallableTypeConstructor =
|
||||||
@@ -181,13 +181,17 @@ private fun preprocessCallableReference(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConstraintSystemBuilder.addConstraintFromLHS(lhsResult: LHSResult.Type, expectedType: UnwrappedType) {
|
private fun ConstraintSystemBuilder.addConstraintFromLHS(
|
||||||
|
argument: CallableReferenceKotlinCallArgument,
|
||||||
|
lhsResult: LHSResult.Type,
|
||||||
|
expectedType: UnwrappedType
|
||||||
|
) {
|
||||||
if (!ReflectionTypes.isNumberedTypeWithOneOrMoreNumber(expectedType)) return
|
if (!ReflectionTypes.isNumberedTypeWithOneOrMoreNumber(expectedType)) return
|
||||||
|
|
||||||
val lhsType = lhsResult.unboundDetailedReceiver.stableType
|
val lhsType = lhsResult.unboundDetailedReceiver.stableType
|
||||||
val expectedTypeProjectionForLHS = expectedType.arguments.first()
|
val expectedTypeProjectionForLHS = expectedType.arguments.first()
|
||||||
val expectedTypeForLHS = expectedTypeProjectionForLHS.type
|
val expectedTypeForLHS = expectedTypeProjectionForLHS.type
|
||||||
val constraintPosition = LHSArgumentConstraintPosition(lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
|
val constraintPosition = LHSArgumentConstraintPosition(argument, lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
|
||||||
|
|
||||||
when (expectedTypeProjectionForLHS.projectionKind) {
|
when (expectedTypeProjectionForLHS.projectionKind) {
|
||||||
Variance.INVARIANT -> addEqualityConstraint(lhsType, expectedTypeForLHS, constraintPosition)
|
Variance.INVARIANT -> addEqualityConstraint(lhsType, expectedTypeForLHS, constraintPosition)
|
||||||
|
|||||||
+4
-1
@@ -63,7 +63,10 @@ class KnownTypeParameterConstraintPosition(val typeArgument: KotlinType) : Const
|
|||||||
override fun toString() = "TypeArgument $typeArgument"
|
override fun toString() = "TypeArgument $typeArgument"
|
||||||
}
|
}
|
||||||
|
|
||||||
class LHSArgumentConstraintPosition(val receiver: DetailedReceiver) : ConstraintPosition() {
|
class LHSArgumentConstraintPosition(
|
||||||
|
val argument: CallableReferenceKotlinCallArgument,
|
||||||
|
val receiver: DetailedReceiver
|
||||||
|
) : ConstraintPosition() {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "LHS receiver $receiver"
|
return "LHS receiver $receiver"
|
||||||
}
|
}
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
package test
|
||||||
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val bla: CharSequence get() = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class B<T>(val x: T)
|
||||||
|
fun <K, V> B<K>.foo(p: KProperty1<K, V>) {}
|
||||||
|
|
||||||
|
class C : A
|
||||||
|
|
||||||
|
fun <R : A> B<R>.test(){
|
||||||
|
<!INAPPLICABLE_CANDIDATE!>foo<!>(C::bla)
|
||||||
|
}
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
package test
|
||||||
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val bla: CharSequence get() = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class B<T>(val x: T)
|
||||||
|
fun <K, V> B<K>.foo(p: KProperty1<K, V>) {}
|
||||||
|
|
||||||
|
class C : A
|
||||||
|
|
||||||
|
fun <R : A> B<R>.test(){
|
||||||
|
foo(<!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>C::bla<!>)
|
||||||
|
}
|
||||||
@@ -1796,6 +1796,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("constraintFromLHSWithCorrectDirectionError.kt")
|
||||||
|
public void testConstraintFromLHSWithCorrectDirectionError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
||||||
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||||
|
|||||||
Generated
+5
@@ -1791,6 +1791,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("constraintFromLHSWithCorrectDirectionError.kt")
|
||||||
|
public void testConstraintFromLHSWithCorrectDirectionError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
|
||||||
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user