Skip to content

Commit

Permalink
K2: build outer classes sequence in FirImplicitBodyResolve properly
Browse files Browse the repository at this point in the history
Before this commit, we used classId-based methods which didn't work
correctly on local classes / objects, thus provoking exceptions.
Now we use lookupTag-based methods which don't have such problems.

#KT-67993 Fixed

(cherry picked from commit 865f6fa)
  • Loading branch information
mglukhikh authored and qodana-bot committed May 8, 2024
1 parent afc5b49 commit b239239
Show file tree
Hide file tree
Showing 29 changed files with 217 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.resolve.FirRegularTowerDataContexts
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.AdapterForResolveProcessor
import org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
Expand Down Expand Up @@ -310,9 +311,10 @@ open class ReturnTypeCalculatorWithJump(
val file = provider.getFirCallableContainerFile(symbol)
val script = file?.declarations?.firstIsInstanceOrNull<FirScript>()

val outerClasses = generateSequence(symbol.containingClassLookupTag()?.classId) { classId ->
classId.outerClassId
}.mapTo(mutableListOf()) { provider.getFirClassifierByFqName(it) }
val containingClassLookupTag = symbol.containingClassLookupTag()
val outerClasses = generateSequence(containingClassLookupTag) { lookupTag ->
lookupTag.toSymbol(session)?.getContainingClassLookupTag()
}.mapTo(mutableListOf()) { it.toSymbol(session)?.fir }

if (file == null || outerClasses.any { it == null }) {
return buildErrorTypeRef {
Expand Down
32 changes: 32 additions & 0 deletions compiler/testData/codegen/box/builderInference/issues/kt67993.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ISSUE: KT-67993
// IGNORE_REVERSED_RESOLVE
// IGNORE_NON_REVERSED_RESOLVE
// Reason: see KT-68031

class Builder<T> {
var res: T? = null

fun add(x: T) {
res = x
}
}

fun <T> foo(build: Builder<T>.() -> Unit): T {
return Builder<T>().apply(build).res!!
}

class C {
val a = foo {
object {
fun bar() {
add(foo())
}

private fun foo() = "OK"
}.bar()
}
}

fun box(): String {
return C().a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// FIR_IDENTICAL
// ISSUE: KT-67993
// IGNORE_REVERSED_RESOLVE
// IGNORE_NON_REVERSED_RESOLVE
// Reason: see KT-68031

class Builder<T> {
fun add(x: T) {}
}

fun <T> foo(build: Builder<T>.() -> Unit) {
Builder<T>().apply(build)
}

class C {
val a = foo {
object {
fun bar() {
add(foo())
}

private fun foo() = "..."
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b239239

Please sign in to comment.