[NI] Fix 'only input type' check for intersection types
Check worked incorrectly in case when argument type and expected type are the same intersection type, which is possible for local variables without explicit type declaration.
This commit is contained in:
+3
-5
@@ -275,11 +275,9 @@ class NewConstraintSystemImpl(
|
||||
if (variableWithConstraints == null || variableWithConstraints.typeVariable.safeAs<NewTypeVariable>()?.hasOnlyInputTypesAnnotation() != true ) return
|
||||
val projectedInputCallTypes = variableWithConstraints.projectedInputCallTypes
|
||||
val resultTypeIsInputType = projectedInputCallTypes.any { inputType ->
|
||||
val constructor = inputType.constructor
|
||||
if (constructor is IntersectionTypeConstructor)
|
||||
constructor.supertypes.any { NewKotlinTypeChecker.Default.equalTypes(resultType, it) }
|
||||
else
|
||||
NewKotlinTypeChecker.Default.equalTypes(resultType, inputType)
|
||||
NewKotlinTypeChecker.Default.equalTypes(resultType, inputType) ||
|
||||
inputType.constructor is IntersectionTypeConstructor
|
||||
&& inputType.constructor.supertypes.any { NewKotlinTypeChecker.Default.equalTypes(resultType, it) }
|
||||
}
|
||||
if (!resultTypeIsInputType) {
|
||||
addError(OnlyInputTypesDiagnostic(variableWithConstraints.typeVariable as NewTypeVariable))
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun test() {
|
||||
val u = when (true) {
|
||||
true -> 42
|
||||
else -> 1.0
|
||||
}
|
||||
|
||||
assertEquals(42, u)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
+5
@@ -2716,6 +2716,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionInputType.kt")
|
||||
public void testIntersectionInputType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt11266.kt")
|
||||
public void testKt11266() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.kt");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2716,6 +2716,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionInputType.kt")
|
||||
public void testIntersectionInputType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt11266.kt")
|
||||
public void testKt11266() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.kt");
|
||||
|
||||
Reference in New Issue
Block a user