diff --git a/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.kt b/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.kt index c3d17e3cef4..a1f6850c438 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.Variance class MainFunctionDetector { - private val getFunctionDescriptor: (KtNamedFunction) -> FunctionDescriptor + private val getFunctionDescriptor: (KtNamedFunction) -> FunctionDescriptor? /** Assumes that the function declaration is already resolved and the descriptor can be found in the `bindingContext`. */ constructor(bindingContext: BindingContext) { @@ -38,7 +38,7 @@ class MainFunctionDetector { } } - constructor(functionResolver: (KtNamedFunction) -> FunctionDescriptor) { + constructor(functionResolver: (KtNamedFunction) -> FunctionDescriptor?) { this.getFunctionDescriptor = functionResolver } @@ -74,7 +74,8 @@ class MainFunctionDetector { return false } - return isMain(getFunctionDescriptor(function), checkJvmStaticAnnotation) + val functionDescriptor = getFunctionDescriptor(function) ?: return false + return isMain(functionDescriptor, checkJvmStaticAnnotation) } fun getMainFunction(module: ModuleDescriptor): FunctionDescriptor? = getMainFunction(module, module.getPackage(FqName.ROOT)) diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerContributor.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerContributor.kt index d3c801fbd15..5c8de8c80b8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerContributor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerContributor.kt @@ -22,7 +22,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.MainFunctionDetector -import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.psi.KtNamedFunction @@ -32,8 +32,8 @@ class KotlinRunLineMarkerContributor : RunLineMarkerContributor() { if (function.nameIdentifier != element) return null - val detector = MainFunctionDetector { function -> - function.resolveToDescriptor() as FunctionDescriptor + val detector = MainFunctionDetector { someFunction -> + someFunction.resolveToDescriptorIfAny() as? FunctionDescriptor } if (detector.isMain(function)) {