提交 58a5f4f9 编写于 作者: I Ilya Kirillov

FIR IDE: do not fail on building anonymous function symbol

上级 b838ba8c
......@@ -35,7 +35,7 @@ internal class HLRedundantUnitReturnTypeInspection :
override val inputProvider = inputProvider<KtNamedFunction, CallableReturnTypeUpdaterApplicator.Type> { function ->
when {
function.getFunctionSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT
function.getFunctionLikeSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT
else -> null
}
}
......
......@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.psi.*
abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) {
is KtParameter -> getParameterSymbol(psi)
is KtNamedFunction -> getFunctionSymbol(psi)
is KtNamedFunction -> getFunctionLikeSymbol(psi)
is KtConstructor<*> -> getConstructorSymbol(psi)
is KtTypeParameter -> getTypeParameterSymbol(psi)
is KtTypeAlias -> getTypeAliasSymbol(psi)
......@@ -32,7 +32,7 @@ abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol
abstract fun getFileSymbol(psi: KtFile): KtFileSymbol
abstract fun getFunctionSymbol(psi: KtNamedFunction): KtFunctionSymbol
abstract fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol
abstract fun getConstructorSymbol(psi: KtConstructor<*>): KtConstructorSymbol
abstract fun getTypeParameterSymbol(psi: KtTypeParameter): KtTypeParameterSymbol
abstract fun getTypeAliasSymbol(psi: KtTypeAlias): KtTypeAliasSymbol
......@@ -57,8 +57,14 @@ interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
fun KtParameter.getParameterSymbol(): KtValueParameterSymbol =
analysisSession.symbolProvider.getParameterSymbol(this)
fun KtNamedFunction.getFunctionSymbol(): KtFunctionSymbol =
analysisSession.symbolProvider.getFunctionSymbol(this)
/**
* Creates [KtFunctionLikeSymbol] by [KtNamedFunction]
*
* If [KtNamedFunction.getName] is `null` then returns [KtAnonymousFunctionSymbol]
* Otherwise, returns [KtFunctionSymbol]
*/
fun KtNamedFunction.getFunctionLikeSymbol(): KtFunctionLikeSymbol =
analysisSession.symbolProvider.getFunctionLikeSymbol(this)
fun KtConstructor<*>.getConstructorSymbol(): KtConstructorSymbol =
analysisSession.symbolProvider.getConstructorSymbol(this)
......
......@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.frontend.api.fir.symbols
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.renderWithType
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState
......@@ -43,9 +44,13 @@ internal class KtFirSymbolProvider(
firSymbolBuilder.buildFileSymbol(psi.getFirFile(resolveState))
}
override fun getFunctionSymbol(psi: KtNamedFunction): KtFunctionSymbol = withValidityAssertion {
psi.withFirDeclarationOfType<FirSimpleFunction, KtFunctionSymbol>(resolveState) {
firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(it)
override fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol = withValidityAssertion {
psi.withFirDeclarationOfType<FirFunction<*>, KtFunctionLikeSymbol>(resolveState) { fir ->
when (fir) {
is FirSimpleFunction -> firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(fir)
is FirAnonymousFunction -> firSymbolBuilder.functionLikeBuilder.buildAnonymousFunctionSymbol(fir)
else -> error("Unexpected ${fir.renderWithType()}")
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册