KT-7433 Type inference pushes Unit inside generic function with lower bound constraint
#KT-7433 Fixed #KT-7351 Fixed
This commit is contained in:
@@ -140,14 +140,6 @@ public class CallCompleter(
|
||||
val returnType = getCandidateDescriptor().getReturnType()
|
||||
if (returnType != null) {
|
||||
getConstraintSystem()!!.addSupertypeConstraint(expectedType, returnType, EXPECTED_TYPE_POSITION.position())
|
||||
|
||||
if (expectedType === TypeUtils.UNIT_EXPECTED_TYPE) {
|
||||
updateSystemIfSuccessful {
|
||||
system ->
|
||||
system.addSupertypeConstraint(KotlinBuiltIns.getInstance().getUnitType(), returnType, EXPECTED_TYPE_POSITION.position())
|
||||
system.getStatus().isSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val constraintSystemCompleter = trace[CONSTRAINT_SYSTEM_COMPLETER, getCall().getCalleeExpression()]
|
||||
@@ -162,6 +154,14 @@ public class CallCompleter(
|
||||
|
||||
(getConstraintSystem() as ConstraintSystemImpl).processDeclaredBoundConstraints()
|
||||
|
||||
if (returnType != null && expectedType === TypeUtils.UNIT_EXPECTED_TYPE) {
|
||||
updateSystemIfSuccessful {
|
||||
system ->
|
||||
system.addSupertypeConstraint(KotlinBuiltIns.getInstance().getUnitType(), returnType, EXPECTED_TYPE_POSITION.position())
|
||||
system.getStatus().isSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
setResultingSubstitutor(getConstraintSystem()!!.getResultingSubstitutor())
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
package kt7351
|
||||
|
||||
trait Node
|
||||
|
||||
trait Source<T> {
|
||||
fun f() : T
|
||||
}
|
||||
fun <T, S : Source<T>> S.woo() : T = this.f()
|
||||
|
||||
fun Node.append(block : Source<Int>.() -> Unit) {
|
||||
}
|
||||
|
||||
fun crashMe(node : Node) {
|
||||
node.append {
|
||||
woo()
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
package kt7351 {
|
||||
internal fun crashMe(/*0*/ node: kt7351.Node): kotlin.Unit
|
||||
internal fun kt7351.Node.append(/*0*/ block: kt7351.Source<kotlin.Int>.() -> kotlin.Unit): kotlin.Unit
|
||||
internal fun </*0*/ T, /*1*/ S : kt7351.Source<T>> S.woo(): T
|
||||
|
||||
internal trait Node {
|
||||
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
|
||||
}
|
||||
|
||||
internal trait Source</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal abstract fun f(): T
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
public inline fun <S, T: S> Iterable<T>.reduce1(operation: (S, T) -> S): S = throw Exception()
|
||||
|
||||
fun test(ints: List<Int>) {
|
||||
val f: () -> Unit = {
|
||||
ints.reduce1 { a, b -> a + b }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ ints: kotlin.List<kotlin.Int>): kotlin.Unit
|
||||
kotlin.inline() public fun </*0*/ S, /*1*/ T : S> kotlin.Iterable<T>.reduce1(/*0*/ operation: (S, T) -> S): S
|
||||
@@ -5834,6 +5834,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt7351ConstraintFromUnitExpectedType.kt")
|
||||
public void testKt7351ConstraintFromUnitExpectedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/kt7351ConstraintFromUnitExpectedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt7433.kt")
|
||||
public void testKt7433() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/kt7433.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notNullConstraintOnNullableType.kt")
|
||||
public void testNotNullConstraintOnNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt");
|
||||
|
||||
Reference in New Issue
Block a user