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