From 4542f3b720f75032dd6880362cd279739caf0513 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 11 Feb 2020 09:02:31 +0300 Subject: [PATCH] [NI] Finish analysis for coerced last lambda expressions if needed --- .../tower/KotlinResolutionCallbacksImpl.kt | 20 +++++++---- .../calls/components/ExternalComponents.kt | 2 ++ .../components/PostponedArgumentsAnalyzer.kt | 17 +++++++-- .../inference/ConstraintSystemBuilder.kt | 12 +++++-- .../nonLocalReturnInConstructorArguments.kt | 2 +- .../coercionToUnitWithLastLambdaExpression.kt | 35 +++++++++++++++++++ .../nonLocalReturns/returnInsideTwoLambdas.kt | 1 - .../diagnostics/tests/AutoCreatedIt.kt | 2 +- .../namedFunAsLastExpressionInBlock.kt | 4 +-- .../extensionMemberInClassObject.kt | 2 +- .../ReceiverByExpectedType.kt | 2 +- .../extensionReceiverTypeMismatch.kt | 4 +-- ...sionWithAnonymousFunctionsAndUnresolved.kt | 4 +-- ...ationOfCoercionToUnitInsideNestedLambda.kt | 2 +- .../tests/inference/recursiveCalls/kt23531.kt | 8 ++--- .../tests/inference/regressions/kt2741.kt | 2 +- .../tests/inference/regressions/kt2841.kt | 2 +- .../tests/inference/regressions/kt2841_it.kt | 2 +- .../inference/regressions/kt2841_it_this.kt | 2 +- .../inference/regressions/kt2841_this.kt | 2 +- .../NoAmbiguityForDifferentFunctionTypes.kt | 2 +- .../diagnostics/tests/regressions/kt30245.kt | 4 +-- .../resolve/invoke/wrongInvokeExtension.kt | 2 +- .../coroutines/inference/kt35684.kt | 2 +- .../testsWithStdLib/resolve/hidesMembers.kt | 2 +- .../testsWithStdLib/resolve/hidesMembers2.kt | 2 +- .../ir/irText/lambdas/nonLocalReturn.txt | 15 ++++---- .../notInferredLambdaReturnType.txt | 4 +-- .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 15 +++++--- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 34 files changed, 145 insertions(+), 55 deletions(-) create mode 100644 compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index 1edbe3df730..b67f5d86775 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -209,23 +209,31 @@ class KotlinResolutionCallbacksImpl( } val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression -> - if (expectedReturnType?.isUnit() == true || hasReturnWithoutExpression) return@let null // coercion to Unit - if (lambdaInfo.returnStatements.any { (expression, _) -> expression == lastExpression }) { return@let null } - // todo lastExpression can be if without else - returnArgumentFound = true val lastExpressionType = trace.getType(lastExpression) val contextInfo = lambdaInfo.lastExpressionInfo val lastExpressionTypeInfo = KotlinTypeInfo(lastExpressionType, contextInfo.dataFlowInfoAfter ?: functionTypeInfo.dataFlowInfo) createCallArgument(lastExpression, lastExpressionTypeInfo, contextInfo.lexicalScope, contextInfo.trace) } - returnArguments.addIfNotNull(lastExpressionArgument) + val lastExpressionCoercedToUnit = expectedReturnType?.isUnit() == true || hasReturnWithoutExpression + if (!lastExpressionCoercedToUnit && lastExpressionArgument != null) { + returnArgumentFound = true + returnArguments += lastExpressionArgument + } - return ReturnArgumentsAnalysisResult(ReturnArgumentsInfo(returnArguments, returnArgumentFound), coroutineSession) + return ReturnArgumentsAnalysisResult( + ReturnArgumentsInfo( + returnArguments, + lastExpressionArgument, + lastExpressionCoercedToUnit, + returnArgumentFound + ), + coroutineSession + ) } private fun getLastDeparentesizedExpression(psiCallArgument: PSIKotlinCallArgument): KtExpression? { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 35704ec4d88..0bad519357c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -47,6 +47,8 @@ interface KotlinResolutionStatelessCallbacks { data class ReturnArgumentsInfo( val nonErrorArguments: List, + val lastExpression: KotlinCallArgument?, + val lastExpressionCoercedToUnit: Boolean, val returnArgumentsExist: Boolean ) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt index 234ef057e50..c28eadfcb95 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt @@ -13,7 +13,9 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument -import org.jetbrains.kotlin.resolve.calls.inference.model.* +import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition +import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPosition import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.model.* @@ -128,9 +130,18 @@ class PostponedArgumentsAnalyzer( stubsForPostponedVariables.cast() ) - returnArgumentsInfo.nonErrorArguments.forEach { c.addSubsystemFromArgument(it) } + val returnArguments = returnArgumentsInfo.nonErrorArguments + returnArguments.forEach { c.addSubsystemFromArgument(it) } - val subResolvedKtPrimitives = returnArgumentsInfo.nonErrorArguments.map { + val lastExpression = returnArgumentsInfo.lastExpression + val allReturnArguments = + if (lastExpression != null && returnArgumentsInfo.lastExpressionCoercedToUnit && c.addSubsystemFromArgument(lastExpression)) { + returnArguments + lastExpression + } else { + returnArguments + } + + val subResolvedKtPrimitives = allReturnArguments.map { resolveKtPrimitive( c.getBuilder(), it, lambda.returnType.let(::substitute), diagnosticHolder, ReceiverInfo.notReceiver, convertedType = null ) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt index cab322b2262..24532c5f13f 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt @@ -68,11 +68,17 @@ fun ConstraintSystemBuilder.addSubtypeConstraintIfCompatible( } -fun PostponedArgumentsAnalyzer.Context.addSubsystemFromArgument(argument: KotlinCallArgument?) { - when (argument) { - is SubKotlinCallArgument -> addOtherSystem(argument.callResult.constraintSystem) +fun PostponedArgumentsAnalyzer.Context.addSubsystemFromArgument(argument: KotlinCallArgument?): Boolean { + return when (argument) { + is SubKotlinCallArgument -> { + addOtherSystem(argument.callResult.constraintSystem) + true + } + is CallableReferenceKotlinCallArgument -> { addSubsystemFromArgument(argument.lhsResult.safeAs()?.lshCallArgument) } + + else -> false } } diff --git a/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt index 9ea1f6113c3..56bd5bf0edb 100644 --- a/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt +++ b/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt @@ -1,4 +1,4 @@ -// !LANGUAGE: -NormalizeConstructorCalls -NewInference +// !LANGUAGE: -NormalizeConstructorCalls // IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt b/compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt new file mode 100644 index 00000000000..b80fd3ffe35 --- /dev/null +++ b/compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt @@ -0,0 +1,35 @@ +// IGNORE_BACKEND_FIR: JVM_IR + +fun myRun(action: () -> T): T = action() +fun foo(): String = "foo" + +fun materialize(): K { + result += "K" + return "str" as K +} + +var result = "fail" + +fun test1(n: Number, b: Boolean) { + n.let { + if (b) return@let + + myRun { + result = "O" + foo() + } + } +} + +fun test2(n: Number, b: Boolean) { + n.let { + if (b) return@let + materialize() + } +} + +fun box(): String { + test1(42, false) + test2(42, false) + return result +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt b/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt index 4e1cd0bdae9..92e8535c552 100644 --- a/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt +++ b/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt @@ -1,4 +1,3 @@ -// !LANGUAGE: -NewInference // IGNORE_BACKEND_FIR: JVM_IR fun outer(command: () -> T) : T = command() diff --git a/compiler/testData/diagnostics/tests/AutoCreatedIt.kt b/compiler/testData/diagnostics/tests/AutoCreatedIt.kt index e2cc8a96d80..c7e7b466be3 100644 --- a/compiler/testData/diagnostics/tests/AutoCreatedIt.kt +++ b/compiler/testData/diagnostics/tests/AutoCreatedIt.kt @@ -12,7 +12,7 @@ fun text() { bar2 {} bar2 {1} - bar2 {it} + bar2 {it} bar2 {it -> it} } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt index 455f40aac32..9c6548e0a8a 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt @@ -7,8 +7,8 @@ fun test() { val x = fun named1(x: Int): Int { return 1 } x checkType { _>() } - foo { Int")!>fun named2(): Int {return 1} } - foo({ fun named3() = 1 }) + foo { Int")!>fun named2(): Int {return 1} } + foo({ fun named3() = 1 }) val x1 = if (1 == 1) diff --git a/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.kt b/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.kt index 5c47ae920f3..46f5bc1c2f0 100644 --- a/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.kt +++ b/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.kt @@ -10,7 +10,7 @@ class Foo { } fun main() { - with("", { + with("", { Foo.findByName("") }) with(Foo) { diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.kt index fc4d953d716..14ddcad79dc 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.kt @@ -1,3 +1,3 @@ // !WITH_NEW_INFERENCE fun foo(f: String.() -> Int) {} -val test = foo(fun () = length) \ No newline at end of file +val test = foo(fun () = length) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.kt index ca4983c085b..dc3b18c6bc2 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.kt @@ -6,12 +6,12 @@ class A { class Out fun test(x: A, y: Out) { - with(x) { + with(x) { // TODO: this diagnostic could be replaced with TYPE_MISMATCH_DUE_TO_TYPE_PROJECTION "".foo() y.bar() - with(y) { + with(y) { bar() } } diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt index 58f47c156fd..7b021ff6e25 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt @@ -52,7 +52,7 @@ fun testUnit() { fun testParameter() { takeFnToParameter { } takeFnToParameter { Unit } - takeFnToParameter { unresolved() } + takeFnToParameter { unresolved() } takeFnToParameter { if (true) unresolved() } takeFnToParameter { if (true) unresolved() else unresolved() @@ -66,7 +66,7 @@ fun testParameter() { takeFnToParameter(fun(): Unit { return Unit }) takeFnToParameter(fun() { if (true) return }) takeFnToParameter(fun() { if (true) return Unit }) - takeFnToParameter(fun() = unresolved()) + takeFnToParameter(fun() = unresolved()) takeFnToParameter(fun() { unresolved() }) takeFnToParameter(fun(): Unit { unresolved() }) takeFnToParameter(fun() { return unresolved() }) diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.kt index 9a06b729ab7..05f01522125 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.kt @@ -24,7 +24,7 @@ fun foo(): String? { run { if (true) { - Obj() + Obj() } else if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas } diff --git a/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.kt b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.kt index d95cba78e04..68eeafcea57 100644 --- a/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.kt +++ b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.kt @@ -13,7 +13,7 @@ fun insideJob1() = doTheJob1() suspend fun insideJob2() = doTheJob2() suspend fun insideJob3() = doTheJob3() -fun doTheJob0() = simpleAsync0 { insideJob0() } -fun doTheJob1() = simpleAsync1 { insideJob1() } -suspend fun doTheJob2() = simpleAsync2 { insideJob2() } -suspend fun doTheJob3() = simpleAsync3 { insideJob3() } +fun doTheJob0() = simpleAsync0 { insideJob0() } +fun doTheJob1() = simpleAsync1 { insideJob1() } +suspend fun doTheJob2() = simpleAsync2 { insideJob2() } +suspend fun doTheJob3() = simpleAsync3 { insideJob3() } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt index 2a0ce85fd4b..dc6a3ce7806 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt @@ -9,5 +9,5 @@ fun _arrayList(vararg values: T) : List = throw Ex class _Pair(val a: A) fun test() { - _arrayList(_Pair(1))._sortBy { it -> xxx } + _arrayList(_Pair(1))._sortBy { it -> xxx } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt index f90b960a5d3..5337e371458 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt @@ -10,7 +10,7 @@ public inline fun T.use1(block: (T)-> R) : R { } fun main() { - C().use1 { + C().use1 { w -> // ERROR here x } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt index ea9c0fdbe08..1e406e58d0d 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt @@ -13,7 +13,7 @@ public inline fun T.use(block: (t: T)-> R) : R { } fun test() { - C().use { + C().use { it.close() x } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt index fdc07d55efa..6c635f87ad7 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt @@ -13,7 +13,7 @@ public inline fun use(t: T, block: T.(T)-> R) : R { } fun test() { - use(C()) { + use(C()) { this.close() it.close() xx diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt index 95c45ed9824..116a2269643 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt @@ -13,7 +13,7 @@ public inline fun T.use(block: T.()-> R) : R { } fun test() { - C().use { + C().use { this.close() x } diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt index 2754ed2d2c0..274c1ba1e68 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt @@ -10,7 +10,7 @@ fun T.foo(block: (T)-> R) = block fun T.foo(block: (T, T)-> R) = block fun main() { - C().foo { // no ambiguity here + C().foo { // no ambiguity here www -> xs } diff --git a/compiler/testData/diagnostics/tests/regressions/kt30245.kt b/compiler/testData/diagnostics/tests/regressions/kt30245.kt index 6fa6187ce16..09b46b1d116 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt30245.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt30245.kt @@ -78,8 +78,8 @@ fun test2() { // to extension lambda 1 // val w27 = W2 { i, s: String -> i + s.length } // overload oi- ni- // val i27: E1 = id { i, s: String -> i + s.length } // overload oi- ni- - val w28 = W2 { i: Int, s -> i + s.length } // oi- ni- - val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- + val w28 = W2 { i: Int, s -> i + s.length } // oi- ni- + val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- val w29 = W2 { i: Int, s: String -> i + s.length } // oi- ni- val i29: E1 = id { i: Int, s: String -> i + s.length } // oi+ ni+ diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt index ef06d8b9456..399dee6ccc6 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt @@ -13,7 +13,7 @@ fun test(a: A, b: B) { b.(a)() - with(b) { + with(b) { val y: Int = a() (a)() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.kt index cc35c3553ff..98b317b6d2c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.kt @@ -21,7 +21,7 @@ fun test_2() { fun test_3() { sequence { yield(materialize()) - materialize() + materialize() } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.kt index 40b8ed86d6b..e593bbccd40 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.kt @@ -42,7 +42,7 @@ fun test(a: A) { a.forEach("") - with(a) { + with(a) { forEach() checkType { _() } forEach(1) checkType { _() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.kt index 7569b320870..0781d51bab5 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.kt @@ -37,7 +37,7 @@ fun test2(a: A) { a.forEach() checkType { _() } a.forEach(1) - with(a) { + with(a) { forEach() checkType { _() } forEach(1) } diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt index 293fd6c32aa..80eec40ce6c 100644 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt @@ -33,14 +33,13 @@ 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 - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Any? origin=null - : kotlin.Any? - 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' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=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' + 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 BLOCK_BODY diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.txt b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.txt index cfa920bc036..240f16b793c 100644 --- a/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.txt +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.txt @@ -8,7 +8,7 @@ fun test() { Resolved call: Candidate descriptor: fun foo(f: () -> T): Unit defined in root package -Resulting descriptor: fun foo(f: () -> ???): Unit defined in root package +Resulting descriptor: fun foo(f: () -> Unit): Unit defined in root package Explicit receiver kind = NO_EXPLICIT_RECEIVER Dispatch receiver = NO_RECEIVER @@ -16,4 +16,4 @@ Extension receiver = NO_RECEIVER Value arguments mapping: -SUCCESS f : () -> ??? = { b } +SUCCESS f : () -> Unit = { b } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 7f6d61c489d..251c118dbbd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12697,6 +12697,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 50aeeeb9c03..0f8c8080d41 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12697,6 +12697,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); @@ -19427,6 +19432,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/properties/augmentedAssignmentsAndIncrements.kt"); } + @TestMetadata("genericWithSameName.kt") + public void ignoreGenericWithSameName() throws Exception { + runTest("compiler/testData/codegen/box/properties/genericWithSameName.kt"); + } + @TestMetadata("sideEffectInTopLevelInitializerMultiModule.kt") public void ignoreSideEffectInTopLevelInitializerMultiModule() throws Exception { runTest("compiler/testData/codegen/box/properties/sideEffectInTopLevelInitializerMultiModule.kt"); @@ -19560,11 +19570,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/properties/genericPropertyMultiModule.kt"); } - @TestMetadata("genericWithSameName.kt") - public void testGenericWithSameName() throws Exception { - runTest("compiler/testData/codegen/box/properties/genericWithSameName.kt"); - } - @TestMetadata("initOrderMultiModule.kt") public void testInitOrderMultiModule() throws Exception { runTest("compiler/testData/codegen/box/properties/initOrderMultiModule.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 9da6334bf4e..24bdd7321c1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -11572,6 +11572,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index d8227c0116b..812671bf50e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11572,6 +11572,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 0a058ba309a..7c4d953ed90 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -9942,6 +9942,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 05574fef1d4..0c6f22c8bff 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -10007,6 +10007,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); } + @TestMetadata("coercionToUnitWithLastLambdaExpression.kt") + public void testCoercionToUnitWithLastLambdaExpression() throws Exception { + runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");