@@ -97,7 +97,7 @@ class LightTreeRawFirDeclarationBuilder(
97
97
}
98
98
IMPORT_LIST -> importList + = convertImportDirectives(child)
99
99
CLASS -> firDeclarationList + = convertClass(child)
100
- FUN -> firDeclarationList + = convertFunctionDeclaration(child) as FirDeclaration
100
+ FUN -> firDeclarationList + = convertFunctionDeclaration(child, headerCompilationMode ) as FirDeclaration
101
101
KtNodeTypes .PROPERTY -> firDeclarationList + = convertPropertyDeclaration(child)
102
102
TYPEALIAS -> firDeclarationList + = convertTypeAlias(child)
103
103
OBJECT_DECLARATION -> firDeclarationList + = convertClass(child)
@@ -1923,7 +1923,7 @@ class LightTreeRawFirDeclarationBuilder(
1923
1923
/* *
1924
1924
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunction
1925
1925
*/
1926
- fun convertFunctionDeclaration (functionDeclaration : LighterASTNode ): FirStatement {
1926
+ fun convertFunctionDeclaration (functionDeclaration : LighterASTNode , generateHeaders : Boolean = false ): FirStatement {
1927
1927
var modifiers: ModifierList ? = null
1928
1928
var identifier: String? = null
1929
1929
var valueParametersList: LighterASTNode ? = null
@@ -1940,6 +1940,8 @@ class LightTreeRawFirDeclarationBuilder(
1940
1940
identifier = it.asText
1941
1941
}
1942
1942
1943
+ var headerMode = generateHeaders
1944
+
1943
1945
val isLocal = isCallableLocal(functionDeclaration) { getParent() }
1944
1946
val functionSource = functionDeclaration.toFirSourceElement()
1945
1947
val isAnonymousFunction = identifier == null && isLocal
@@ -1971,6 +1973,11 @@ class LightTreeRawFirDeclarationBuilder(
1971
1973
1972
1974
val calculatedModifiers = modifiers ? : ModifierList ()
1973
1975
1976
+ if (calculatedModifiers.hasInline()) {
1977
+ // We need to disable header mode for inline functions.
1978
+ headerMode = false
1979
+ }
1980
+
1974
1981
if (returnType == null ) {
1975
1982
returnType =
1976
1983
if (block != null || ! hasEqToken) implicitUnitType
@@ -2066,7 +2073,7 @@ class LightTreeRawFirDeclarationBuilder(
2066
2073
2067
2074
val allowLegacyContractDescription = outerContractDescription == null
2068
2075
val bodyWithContractDescription = withForcedLocalContext {
2069
- convertFunctionBody(block, expression, allowLegacyContractDescription)
2076
+ convertFunctionBody(block, expression, allowLegacyContractDescription, headerMode )
2070
2077
}
2071
2078
this .body = bodyWithContractDescription.first
2072
2079
val contractDescription = outerContractDescription ? : bodyWithContractDescription.second
@@ -2103,11 +2110,12 @@ class LightTreeRawFirDeclarationBuilder(
2103
2110
private fun convertFunctionBody (
2104
2111
blockNode : LighterASTNode ? ,
2105
2112
expression : LighterASTNode ? ,
2106
- allowLegacyContractDescription : Boolean
2113
+ allowLegacyContractDescription : Boolean ,
2114
+ generateHeaders : Boolean = false,
2107
2115
): Pair <FirBlock ?, FirContractDescription ?> {
2108
2116
return when {
2109
2117
blockNode != null -> {
2110
- val block = convertBlock(blockNode)
2118
+ val block = convertBlock(blockNode) // We might be able to process only the contract statement in the body.
2111
2119
val contractDescription = runIf(allowLegacyContractDescription) {
2112
2120
val blockSource = block.source
2113
2121
val diagnostic = when {
@@ -2117,7 +2125,11 @@ class LightTreeRawFirDeclarationBuilder(
2117
2125
}
2118
2126
processLegacyContractDescription(block, diagnostic)
2119
2127
}
2120
- block to contractDescription
2128
+ if (generateHeaders) {
2129
+ null to contractDescription // We want to preserve the contract info when processing as headers.
2130
+ } else {
2131
+ block to contractDescription
2132
+ }
2121
2133
}
2122
2134
expression != null -> FirSingleExpressionBlock (
2123
2135
expressionConverter.getAsFirExpression<FirExpression >(expression, " Function has no body (but should)" ).toReturn()
0 commit comments