FIR IDE: do not fail on building anonymous function symbol
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ internal class HLRedundantUnitReturnTypeInspection :
|
|||||||
|
|
||||||
override val inputProvider = inputProvider<KtNamedFunction, CallableReturnTypeUpdaterApplicator.Type> { function ->
|
override val inputProvider = inputProvider<KtNamedFunction, CallableReturnTypeUpdaterApplicator.Type> { function ->
|
||||||
when {
|
when {
|
||||||
function.getFunctionSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT
|
function.getFunctionLikeSymbol().annotatedType.type.isUnit -> CallableReturnTypeUpdaterApplicator.Type.UNIT
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
||||||
open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) {
|
open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) {
|
||||||
is KtParameter -> getParameterSymbol(psi)
|
is KtParameter -> getParameterSymbol(psi)
|
||||||
is KtNamedFunction -> getFunctionSymbol(psi)
|
is KtNamedFunction -> getFunctionLikeSymbol(psi)
|
||||||
is KtConstructor<*> -> getConstructorSymbol(psi)
|
is KtConstructor<*> -> getConstructorSymbol(psi)
|
||||||
is KtTypeParameter -> getTypeParameterSymbol(psi)
|
is KtTypeParameter -> getTypeParameterSymbol(psi)
|
||||||
is KtTypeAlias -> getTypeAliasSymbol(psi)
|
is KtTypeAlias -> getTypeAliasSymbol(psi)
|
||||||
@@ -32,7 +32,7 @@ abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
|||||||
|
|
||||||
abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol
|
abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol
|
||||||
abstract fun getFileSymbol(psi: KtFile): KtFileSymbol
|
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 getConstructorSymbol(psi: KtConstructor<*>): KtConstructorSymbol
|
||||||
abstract fun getTypeParameterSymbol(psi: KtTypeParameter): KtTypeParameterSymbol
|
abstract fun getTypeParameterSymbol(psi: KtTypeParameter): KtTypeParameterSymbol
|
||||||
abstract fun getTypeAliasSymbol(psi: KtTypeAlias): KtTypeAliasSymbol
|
abstract fun getTypeAliasSymbol(psi: KtTypeAlias): KtTypeAliasSymbol
|
||||||
@@ -57,8 +57,14 @@ interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
|||||||
fun KtParameter.getParameterSymbol(): KtValueParameterSymbol =
|
fun KtParameter.getParameterSymbol(): KtValueParameterSymbol =
|
||||||
analysisSession.symbolProvider.getParameterSymbol(this)
|
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 =
|
fun KtConstructor<*>.getConstructorSymbol(): KtConstructorSymbol =
|
||||||
analysisSession.symbolProvider.getConstructorSymbol(this)
|
analysisSession.symbolProvider.getConstructorSymbol(this)
|
||||||
|
|||||||
+8
-3
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.frontend.api.fir.symbols
|
package org.jetbrains.kotlin.idea.frontend.api.fir.symbols
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
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.resolve.providers.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState
|
import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState
|
||||||
@@ -43,9 +44,13 @@ internal class KtFirSymbolProvider(
|
|||||||
firSymbolBuilder.buildFileSymbol(psi.getFirFile(resolveState))
|
firSymbolBuilder.buildFileSymbol(psi.getFirFile(resolveState))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFunctionSymbol(psi: KtNamedFunction): KtFunctionSymbol = withValidityAssertion {
|
override fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol = withValidityAssertion {
|
||||||
psi.withFirDeclarationOfType<FirSimpleFunction, KtFunctionSymbol>(resolveState) {
|
psi.withFirDeclarationOfType<FirFunction<*>, KtFunctionLikeSymbol>(resolveState) { fir ->
|
||||||
firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(it)
|
when (fir) {
|
||||||
|
is FirSimpleFunction -> firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(fir)
|
||||||
|
is FirAnonymousFunction -> firSymbolBuilder.functionLikeBuilder.buildAnonymousFunctionSymbol(fir)
|
||||||
|
else -> error("Unexpected ${fir.renderWithType()}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user