From 7ee71450bc56956c250caa379e69441ea3b6ea86 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Tue, 24 Dec 2019 14:51:39 +0300 Subject: [PATCH] [NI] Discriminate `Nothing?` result type from nullability constraints Nullability constraints should not be chosen when proper argument constraints for variables in contravariant position present. ^KT-32106 Fixed ^KT-33166 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 10 +++++++ .../components/ConstraintIncorporator.kt | 5 +++- .../components/ConstraintInjector.kt | 14 +++++++--- .../components/ResultTypeResolver.kt | 22 +++++++++------- .../inference/model/ConstraintStorage.kt | 3 ++- .../model/MutableConstraintStorage.kt | 3 ++- .../preferArgumentToNullability.fir.kt | 15 +++++++++++ .../preferArgumentToNullability.kt | 15 +++++++++++ .../preferArgumentToNullability.txt | 26 +++++++++++++++++++ .../nestedCalls/preferNothingToBound.fir.kt | 3 +++ .../nestedCalls/preferNothingToBound.kt | 3 +++ .../nestedCalls/preferNothingToBound.txt | 4 +++ ...erArgumentToNothingFromNullConstant.fir.kt | 12 +++++++++ .../inference/regressions/kt32106.fir.kt | 2 -- .../tests/inference/regressions/kt32106.kt | 2 -- ...nlyInputTypesCommonConstraintSystem.fir.kt | 2 +- .../onlyInputTypesCommonConstraintSystem.kt | 2 +- .../testsWithStdLib/tryCatch/tryExpression.kt | 2 +- .../ir/irText/expressions/whenReturn.fir.txt | 4 +-- .../ir/irText/lambdas/nonLocalReturn.fir.txt | 18 ++++++------- .../diagnostics/notLinked/dfa/pos/4.kt | 2 +- .../checkers/DiagnosticsTestGenerated.java | 10 +++++++ .../DiagnosticsUsingJavacTestGenerated.java | 10 +++++++ 23 files changed, 154 insertions(+), 35 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.txt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.txt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.fir.kt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index fc88b841d55..56c5f53998f 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -10604,6 +10604,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte public void testNontrivialCallExpression() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.kt"); } + + @TestMetadata("preferArgumentToNullability.kt") + public void testPreferArgumentToNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt"); + } + + @TestMetadata("preferNothingToBound.kt") + public void testPreferNothingToBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/nothingType") diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt index 1fac1dba67f..ff36dbbed62 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt @@ -175,7 +175,10 @@ class ConstraintIncorporator( val inputTypePosition = if (baseConstraint.position.from is OnlyInputTypeConstraintPosition) baseConstraint.position else null - addNewIncorporatedConstraint(targetVariable, newConstraint, ConstraintContext(kind, derivedFrom, inputTypePosition)) + val isNullabilityConstraint = isUsefulForNullabilityConstraint && newConstraint.isNullableNothing() + val constraintContext = ConstraintContext(kind, derivedFrom, inputTypePosition, isNullabilityConstraint) + + addNewIncorporatedConstraint(targetVariable, newConstraint, constraintContext) } fun Context.containsConstrainingTypeWithoutProjection( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index ab284eb30b9..0d15a3dd49d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -178,7 +178,7 @@ class ConstraintInjector( val typeVariable = c.allTypeVariables[typeVariableConstructor] ?: error("Should by type variableConstructor: $typeVariableConstructor. ${c.allTypeVariables.values}") - addNewIncorporatedConstraint(typeVariable, type, ConstraintContext(kind, emptySet())) + addNewIncorporatedConstraint(typeVariable, type, ConstraintContext(kind, emptySet(), isNullabilityConstraint = false)) } // from ConstraintIncorporator.Context @@ -194,7 +194,7 @@ class ConstraintInjector( type: KotlinTypeMarker, constraintContext: ConstraintContext ) { - val (kind, derivedFrom, inputTypePosition) = constraintContext + val (kind, derivedFrom, inputTypePosition, isNullabilityConstraint) = constraintContext var targetType = type if (targetType.isUninferredParameter()) { @@ -231,7 +231,12 @@ class ConstraintInjector( } } - possibleNewConstraints.add(typeVariable to Constraint(kind, targetType, position, derivedFrom = derivedFrom)) + val newConstraint = Constraint( + kind, targetType, position, + derivedFrom = derivedFrom, + isNullabilityConstraint = isNullabilityConstraint + ) + possibleNewConstraints.add(typeVariable to newConstraint) inputTypePosition?.let { preservedInputTypePositions.add(it) } } @@ -264,5 +269,6 @@ class ConstraintInjector( data class ConstraintContext( val kind: ConstraintKind, val derivedFrom: Set, - val inputTypePosition: ConstraintPosition? = null + val inputTypePosition: ConstraintPosition? = null, + val isNullabilityConstraint: Boolean ) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt index 651d3f33ce3..505b18018d0 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt @@ -80,23 +80,27 @@ class ResultTypeResolver( } private fun Context.isSuitableType(resultType: KotlinTypeMarker, variableWithConstraints: VariableWithConstraints): Boolean { - for (constraint in variableWithConstraints.constraints) { - if (!isProperType(constraint.type)) continue + val filteredConstraints = variableWithConstraints.constraints.filter { isProperType(it.type) } + for (constraint in filteredConstraints) { if (!checkConstraint(this, constraint.type, constraint.kind, resultType)) return false } - if ( - !trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType) - && isNothingNotSuitableFor(variableWithConstraints.typeVariable) - ) return false + if (!trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType)) { + if (nothingIsForbiddenFor(variableWithConstraints.typeVariable)) return false + if (resultType.isNullableType() && checkSingleLowerNullabilityConstraint(filteredConstraints)) return false + } return true } - private fun isNothingNotSuitableFor(variable: TypeVariableMarker): Boolean { + private fun nothingIsForbiddenFor(variable: TypeVariableMarker): Boolean { val parameterName = variable.safeAs()?.originalTypeParameter?.name ?: return false val isSpecialFunctionParameter = statelessCallbacks?.isSpecialFunctionTypeParameterName(parameterName) ?: false - val isBangBangParameter = isSpecialFunctionParameter && statelessCallbacks?.isExclExclTypeParameterName(parameterName) ?: false - return isSpecialFunctionParameter && !isBangBangParameter + val isFromExclExcl = isSpecialFunctionParameter && statelessCallbacks?.isExclExclTypeParameterName(parameterName) ?: false + return isSpecialFunctionParameter && !isFromExclExcl + } + + private fun checkSingleLowerNullabilityConstraint(constraints: List): Boolean { + return constraints.singleOrNull { it.kind.isLower() }?.isNullabilityConstraint ?: false } private fun Context.findSubType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintStorage.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintStorage.kt index d810ac5ec3d..998afc527f4 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintStorage.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintStorage.kt @@ -68,7 +68,8 @@ class Constraint( val type: KotlinTypeMarker, // flexible types here is allowed val position: IncorporationConstraintPosition, val typeHashCode: Int = type.hashCode(), - val derivedFrom: Set + val derivedFrom: Set, + val isNullabilityConstraint: Boolean ) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt index 34e827eeee0..d9418ab1cc2 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt @@ -68,7 +68,8 @@ class MutableVariableWithConstraints( constraint.type, constraint.position, constraint.typeHashCode, - derivedFrom = constraint.derivedFrom + derivedFrom = constraint.derivedFrom, + isNullabilityConstraint = false ) else constraint diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.fir.kt new file mode 100644 index 00000000000..6e2fd6f3d6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Cls + +abstract class In +class SubIn : In() + +inline fun materialize(): T? = TODO() + +fun transform(transformer: In, data: D): Unit = TODO() + +fun test(subIn: SubIn) { + transform(subIn, materialize()) // D should be inferred to Cls?, not Nothing? +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt new file mode 100644 index 00000000000..6e2fd6f3d6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Cls + +abstract class In +class SubIn : In() + +inline fun materialize(): T? = TODO() + +fun transform(transformer: In, data: D): Unit = TODO() + +fun test(subIn: SubIn) { + transform(subIn, materialize()) // D should be inferred to Cls?, not Nothing? +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.txt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.txt new file mode 100644 index 00000000000..c51cd0c3b3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.txt @@ -0,0 +1,26 @@ +package + +public inline fun materialize(): T? +public fun test(/*0*/ subIn: SubIn): kotlin.Unit +public fun transform(/*0*/ transformer: In, /*1*/ data: D): kotlin.Unit + +public open class Cls { + public constructor Cls() + 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 +} + +public abstract class In { + public constructor In() + 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 +} + +public final class SubIn : In { + public constructor SubIn() + 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 +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.fir.kt new file mode 100644 index 00000000000..b4e1265604a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.fir.kt @@ -0,0 +1,3 @@ +fun id(arg: K): K = arg + +val v = id(null) diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt new file mode 100644 index 00000000000..62d0ef413b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt @@ -0,0 +1,3 @@ +fun id(arg: K): K = arg + +val v = id(null) diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.txt b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.txt new file mode 100644 index 00000000000..63510ce92f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.txt @@ -0,0 +1,4 @@ +package + +public val v: kotlin.Nothing? +public fun id(/*0*/ arg: K): K diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.fir.kt new file mode 100644 index 00000000000..9a37651c984 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE + +class Out(result: T?) + +fun main() { + val a = Out(null) + + a + + var b: Out? = null + b = a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt32106.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt32106.fir.kt index d21d725acbb..e6d5fe87ff3 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt32106.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt32106.fir.kt @@ -1,5 +1,3 @@ -// !LANGUAGE: +NewInference - class Query private constructor( private val result: T?, private val error: Throwable?, diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt32106.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt32106.kt index d21d725acbb..e6d5fe87ff3 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt32106.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt32106.kt @@ -1,5 +1,3 @@ -// !LANGUAGE: +NewInference - class Query private constructor( private val result: T?, private val error: Throwable?, diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.fir.kt index 95456e19661..8c323891011 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.fir.kt @@ -36,7 +36,6 @@ fun testOK(first: First, bound: Bound, second: Second) { strictSelect(OutB(first), OutB(bound)) strictSelect(In(first), In(bound)) strictSelect(InB(first), InB(bound)) - strictSelect(InB(first), InB(second)) // different behaviour in contravariant position val out: Out = strictSelect(Out(first), Out(second)) val outb: OutB = strictSelect(OutB(first), OutB(second)) @@ -49,6 +48,7 @@ fun testFail(first: First, bound: Bound, second: Second) { strictSelect(Inv(first), Inv(bound)) strictSelect(Out(first), Out(second)) strictSelect(In(first), In(second)) + strictSelect(InB(first), InB(second)) strictSelect(Out(Inv(first)), Out(Inv(second))) strictSelect(In(Inv(first)), In(Inv(second))) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.kt index ab8fc179b55..80fbd7071dc 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCommonConstraintSystem.kt @@ -36,7 +36,6 @@ fun testOK(first: First, bound: Bound, second: Second) { strictSelect(OutB(first), OutB(bound)) strictSelect(In(first), In(bound)) strictSelect(InB(first), InB(bound)) - strictSelect(InB(first), InB(second)) // different behaviour in contravariant position val out: Out = strictSelect(Out(first), Out(second)) val outb: OutB = strictSelect(OutB(first), OutB(second)) @@ -49,6 +48,7 @@ fun testFail(first: First, bound: Bound, second: Second) { strictSelect(Inv(first), Inv(bound)) strictSelect(Out(first), Out(second)) strictSelect(In(first), In(second)) + strictSelect(InB(first), InB(second)) strictSelect(Out(Inv(first)), Out(Inv(second))) strictSelect(In(Inv(first)), In(Inv(second))) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt index 23e21dc8dd7..0406ad6da0d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt @@ -27,7 +27,7 @@ fun test1(): Map = run { } fun test2(): Map = run { - try { + try { emptyMap() } catch (e: ExcA) { mapOf("" to "") diff --git a/compiler/testData/ir/irText/expressions/whenReturn.fir.txt b/compiler/testData/ir/irText/expressions/whenReturn.fir.txt index c1068fc5a64..7cd116a9604 100644 --- a/compiler/testData/ir/irText/expressions/whenReturn.fir.txt +++ b/compiler/testData/ir/irText/expressions/whenReturn.fir.txt @@ -2,10 +2,10 @@ FILE fqName: fileName:/whenReturn.kt FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String VALUE_PARAMETER name:grade index:0 type:kotlin.String BLOCK_BODY - BLOCK type=kotlin.String origin=WHEN + BLOCK type=kotlin.Nothing origin=WHEN VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String [val] GET_VAR 'grade: kotlin.String declared in .toString' type=kotlin.String origin=null - WHEN type=kotlin.String origin=WHEN + WHEN type=kotlin.Nothing origin=WHEN BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp_0: kotlin.String [val] declared in .toString' type=kotlin.String origin=null diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.txt index 57946b5adf2..a93f839a725 100644 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.txt +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.txt @@ -1,10 +1,10 @@ FILE fqName: fileName:/nonLocalReturn.kt FUN name:test0 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Unit origin=null - : kotlin.Unit - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null + : kotlin.Nothing + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test0 (): kotlin.Unit declared in ' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit @@ -33,12 +33,12 @@ FILE fqName: fileName:/nonLocalReturn.kt block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Unit origin=null - : kotlin.Unit - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null + : kotlin.Nothing + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3.' + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Nothing declared in .test3.' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit FUN name:testLrmFoo1 visibility:public modality:FINAL <> (ints:kotlin.collections.List) returnType:kotlin.Unit VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt index 608202d6df6..ed19e72e61a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt @@ -285,7 +285,7 @@ fun case_24(a: ((() -> Unit) -> Unit), b: (() -> Unit)) { } // TESTCASE NUMBER: 25 -fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) kotlin.Unit) -> kotlin.Unit & kotlin.Nothing"), DEBUG_INFO_SMARTCAST!>a else {{}}) { +fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) kotlin.Unit) -> kotlin.Unit & kotlin.Nothing")!>a else {{}}) { kotlin.Unit) -> kotlin.Unit")!>a kotlin.Unit) -> kotlin.Unit")!>b } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d2021d36288..8d403195310 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10611,6 +10611,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { public void testNontrivialCallExpression() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.kt"); } + + @TestMetadata("preferArgumentToNullability.kt") + public void testPreferArgumentToNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt"); + } + + @TestMetadata("preferNothingToBound.kt") + public void testPreferNothingToBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/nothingType") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 75b49667932..0f3d404fccd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10606,6 +10606,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing public void testNontrivialCallExpression() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.kt"); } + + @TestMetadata("preferArgumentToNullability.kt") + public void testPreferArgumentToNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferArgumentToNullability.kt"); + } + + @TestMetadata("preferNothingToBound.kt") + public void testPreferNothingToBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nestedCalls/preferNothingToBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/nothingType")