[NI] Fix coercion to Unit for explicitly specified type argument
#KT-25424 Fixed
This commit is contained in:
+2
-2
@@ -25,7 +25,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
// type can be proper if it not contains not fixed type variables
|
// type can be proper if it not contains not fixed type variables
|
||||||
fun canBeProper(type: UnwrappedType): Boolean
|
fun canBeProper(type: UnwrappedType): Boolean
|
||||||
|
|
||||||
fun hasUpperUnitConstraint(type: UnwrappedType): Boolean
|
fun hasUpperOrEqualUnitConstraint(type: UnwrappedType): Boolean
|
||||||
|
|
||||||
// mutable operations
|
// mutable operations
|
||||||
fun addOtherSystem(otherSystem: ConstraintStorage)
|
fun addOtherSystem(otherSystem: ConstraintStorage)
|
||||||
@@ -76,7 +76,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
c.canBeProper(rawReturnType) -> substitute(rawReturnType)
|
c.canBeProper(rawReturnType) -> substitute(rawReturnType)
|
||||||
|
|
||||||
// For Unit-coercion
|
// For Unit-coercion
|
||||||
c.hasUpperUnitConstraint(rawReturnType) -> lambda.returnType.builtIns.unitType
|
c.hasUpperOrEqualUnitConstraint(rawReturnType) -> lambda.returnType.builtIns.unitType
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -289,11 +289,11 @@ class NewConstraintSystemImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PostponedArgumentsAnalyzer.Context
|
// PostponedArgumentsAnalyzer.Context
|
||||||
override fun hasUpperUnitConstraint(type: UnwrappedType): Boolean {
|
override fun hasUpperOrEqualUnitConstraint(type: UnwrappedType): Boolean {
|
||||||
checkState(State.BUILDING, State.COMPLETION, State.FREEZED)
|
checkState(State.BUILDING, State.COMPLETION, State.FREEZED)
|
||||||
|
|
||||||
val constraints = storage.notFixedTypeVariables[type.constructor]?.constraints ?: return false
|
val constraints = storage.notFixedTypeVariables[type.constructor]?.constraints ?: return false
|
||||||
|
|
||||||
return constraints.any { it.kind == ConstraintKind.UPPER && it.type.isUnit() }
|
return constraints.any { (it.kind == ConstraintKind.UPPER || it.kind == ConstraintKind.EQUALITY) && it.type.isUnit() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val f = myRun<Unit> {
|
||||||
|
123
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <R> myRun(block: () -> R): R = block()
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
public fun </*0*/ R> myRun(/*0*/ block: () -> R): R
|
||||||
@@ -9685,6 +9685,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("coercionWithExplicitTypeArgument.kt")
|
||||||
|
public void testCoercionWithExplicitTypeArgument() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("coercionWithoutExpectedType.kt")
|
@TestMetadata("coercionWithoutExpectedType.kt")
|
||||||
public void testCoercionWithoutExpectedType() throws Exception {
|
public void testCoercionWithoutExpectedType() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.kt");
|
||||||
|
|||||||
Generated
+5
@@ -9685,6 +9685,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("coercionWithExplicitTypeArgument.kt")
|
||||||
|
public void testCoercionWithExplicitTypeArgument() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("coercionWithoutExpectedType.kt")
|
@TestMetadata("coercionWithoutExpectedType.kt")
|
||||||
public void testCoercionWithoutExpectedType() throws Exception {
|
public void testCoercionWithoutExpectedType() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user