From 96db6eb94f42c562dc494093d75f6bd3f8fa444c Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Tue, 16 Jan 2024 17:49:03 +0200 Subject: [PATCH] [FIR] Support tailrec safe-calls ^KT-63529 Fixed --- .../checkers/declaration/FirTailrecFunctionChecker.kt | 5 +++-- compiler/testData/diagnostics/tests/tailrec.fir.kt | 8 -------- compiler/testData/diagnostics/tests/tailrec.kt | 1 + 3 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/tailrec.fir.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTailrecFunctionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTailrecFunctionChecker.kt index 5998aa4e27f..7aa39b7d3b4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTailrecFunctionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTailrecFunctionChecker.kt @@ -102,8 +102,9 @@ object FirTailrecFunctionChecker : FirSimpleFunctionChecker() { val hasMore = when (next) { // If exiting another function, then it means this call is inside a nested local function, in which case, it's not a tailrec call. is FunctionExitNode -> return next.fir != tailrecFunction - is JumpNode, is BinaryAndExitNode, is BinaryOrExitNode, is WhenBranchResultExitNode, is WhenExitNode, is BlockExitNode -> - next.hasMoreFollowingInstructions(tailrecFunction) + is JumpNode, is BinaryAndExitNode, is BinaryOrExitNode, is WhenBranchResultExitNode, is WhenExitNode, is BlockExitNode, + is ExitSafeCallNode + -> next.hasMoreFollowingInstructions(tailrecFunction) else -> return true } if (hasMore) return hasMore diff --git a/compiler/testData/diagnostics/tests/tailrec.fir.kt b/compiler/testData/diagnostics/tests/tailrec.fir.kt deleted file mode 100644 index b8a72d4dea1..00000000000 --- a/compiler/testData/diagnostics/tests/tailrec.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ -// ISSUE: KT-63529 - -private tailrec fun Context.findActivityOrNull(): Activity? { - return mBase?.findActivityOrNull() -} -abstract class Context -open class Activity -var mBase: Context = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/tailrec.kt b/compiler/testData/diagnostics/tests/tailrec.kt index 3c3f4cbf54a..b6c1ea62cd8 100644 --- a/compiler/testData/diagnostics/tests/tailrec.kt +++ b/compiler/testData/diagnostics/tests/tailrec.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // ISSUE: KT-63529 private tailrec fun Context.findActivityOrNull(): Activity? {