diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt index 0611d9c890c..9b068ecce16 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt @@ -35,7 +35,7 @@ internal class HLRedundantUnitReturnTypeInspection : override val inputProvider = inputProvider { function -> when { - function.getFunctionSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT + function.getFunctionLikeSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT else -> null } } diff --git a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/KtSymbolProvider.kt b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/KtSymbolProvider.kt index e3ef90f33a8..7d78a83af98 100644 --- a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/KtSymbolProvider.kt +++ b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/KtSymbolProvider.kt @@ -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) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirSymbolProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirSymbolProvider.kt index 798ad50bae8..9102aea545b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirSymbolProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirSymbolProvider.kt @@ -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(resolveState) { - firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(it) + override fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol = withValidityAssertion { + psi.withFirDeclarationOfType, KtFunctionLikeSymbol>(resolveState) { fir -> + when (fir) { + is FirSimpleFunction -> firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(fir) + is FirAnonymousFunction -> firSymbolBuilder.functionLikeBuilder.buildAnonymousFunctionSymbol(fir) + else -> error("Unexpected ${fir.renderWithType()}") + } } }