Skip to content

Conversation

@aviroop-123
Copy link
Contributor

  • Adds more tests for header compilation, specifically nested classes/functions.
  • Fixes for nested function / method declaration.
  • Re-enable LT2Fir function/method body removal & fix for test stub.

@aviroop-123 aviroop-123 requested review from a team as code owners October 30, 2025 21:11
@demiurg906 demiurg906 self-assigned this Oct 31, 2025
@demiurg906 demiurg906 requested review from demiurg906 and removed request for FenstonSingel and mMaxy October 31, 2025 12:18
result.transformReturnTypeRef(transformer, ResolutionMode.UpdateImplicitTypeRef(returnTypeRef))
}
if (session.languageVersionSettings.getFlag(AnalysisFlags.headerMode) && !function.isInline) {
if (session.languageVersionSettings.getFlag(AnalysisFlags.headerMode) && !function.isInline && function.isFromInlineFunction != true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this attribute, actually.
It's enough to check that:

  • header mode is enabled
  • and the function is non local
  • and the function is inline

If the function is local (either real local function or member of a local class), and its contained in the non inline function, it would be removed together with the body of the outer function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you mean. But would this mean we're processing the bodies of the local functions / classes even though it'll get removed at a later stage?

Also, does that mean that we don't need the forceKeepingTheBodyInHeaderMode?

overriddenFunctions.map { it.status as FirResolvedDeclarationStatus },
)
// Once the modality is determined, we can remove the body.
if (session.languageVersionSettings.getFlag(AnalysisFlags.headerMode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument from the other comment also applies here.

Also please use the following formatting in case of long if conditions:

if(
    cond1 &&
        cond2 &&
        cond3
) {
    ...
}

var containerIsExpect: Boolean = false

var containedWithinInlineFunction: Boolean = false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it to forceKeepingTheBodyInHeaderMode.

isExpect: Boolean,
forceLocalContext: Boolean = false,
containedWithinInlineFunction: Boolean? = null,
l: () -> T,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used at call sites

name: Name,
isExpect: Boolean,
containedWithinInlineFunction: Boolean? = null,
l: () -> T,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called only from withChildClassName, so the parameter could be removed from there too.


inline fun <R> withForcedLocalContext(block: () -> R): R {
inline fun <R> withForcedLocalContext(containedWithinInlineFunction: Boolean? = null, block: () -> R): R {
val oldContainedWithinInlineFunction = context.containedWithinInlineFunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my previous comment should be also renamed. Also the default could be changed forceKeepingTheBodyInHeaderMode: Boolean = false.
So the assignment would look like the following:

val oldContainedWithinInlineFunction = context.containedWithinInlineFunction
context.containedWithinInlineFunction = oldContainedWithinInlineFunction || containedWithinInlineFunction

}

fun convertBlockExpressionWithoutBuilding(block: LighterASTNode, kind: KtFakeSourceElementKind? = null): FirBlockBuilder {
fun convertBlockExpressionWithoutBuilding(block: LighterASTNode, kind: KtFakeSourceElementKind? = null, generateHeader: Boolean = false): FirBlockBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Put parameters on separarate lines for readability
  2. Rename generateHeader to convertOnlyFirstStatement
  3. Add a KDoc explaining why it's required

@JetBrains JetBrains deleted a comment from kotlin-safe-merge bot Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants