Fix exception in EE for inline function invocation
#KT-10217 Fixed
This commit is contained in:
@@ -173,7 +173,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun extractAndCompile(codeFragment: KtCodeFragment, sourcePosition: SourcePosition, context: EvaluationContextImpl): CompiledDataDescriptor {
|
private fun extractAndCompile(codeFragment: KtCodeFragment, sourcePosition: SourcePosition, context: EvaluationContextImpl): CompiledDataDescriptor {
|
||||||
codeFragment.checkForErrors(false)
|
codeFragment.checkForErrors()
|
||||||
|
|
||||||
val extractionResult = getFunctionForExtractedFragment(codeFragment, sourcePosition.file, sourcePosition.line)
|
val extractionResult = getFunctionForExtractedFragment(codeFragment, sourcePosition.file, sourcePosition.line)
|
||||||
?: throw IllegalStateException("Code fragment cannot be extracted to function: ${codeFragment.text}")
|
?: throw IllegalStateException("Code fragment cannot be extracted to function: ${codeFragment.text}")
|
||||||
@@ -360,7 +360,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
LOG.debug("File for eval4j:\n${runReadAction { jetFile.text }}")
|
LOG.debug("File for eval4j:\n${runReadAction { jetFile.text }}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val (bindingContext, moduleDescriptor, files) = jetFile.checkForErrors(true)
|
val (bindingContext, moduleDescriptor, files) = jetFile.checkForErrors(true, codeFragment.getContextContainingFile())
|
||||||
|
|
||||||
val generateClassFilter = object : GenerationState.GenerateClassFilter() {
|
val generateClassFilter = object : GenerationState.GenerateClassFilter() {
|
||||||
override fun shouldGeneratePackagePart(jetFile: KtFile) = jetFile == jetFile
|
override fun shouldGeneratePackagePart(jetFile: KtFile) = jetFile == jetFile
|
||||||
@@ -431,7 +431,8 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
throw EvaluateExceptionUtil.createEvaluateException(e)
|
throw EvaluateExceptionUtil.createEvaluateException(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtFile.checkForErrors(analyzeInlineFunctions: Boolean): ExtendedAnalysisResult {
|
// contextFile must be NotNull when analyzeInlineFunctions = true
|
||||||
|
private fun KtFile.checkForErrors(analyzeInlineFunctions: Boolean = false, contextFile: KtFile? = null): ExtendedAnalysisResult {
|
||||||
return runReadAction {
|
return runReadAction {
|
||||||
try {
|
try {
|
||||||
AnalyzingUtils.checkForSyntacticErrors(this)
|
AnalyzingUtils.checkForSyntacticErrors(this)
|
||||||
@@ -440,8 +441,10 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
throw EvaluateExceptionUtil.createEvaluateException(e.message)
|
throw EvaluateExceptionUtil.createEvaluateException(e.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolutionFacade = KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this, createFlexibleTypesFile()))
|
val filesToAnalyze = if (contextFile == null) listOf(this) else listOf(this, contextFile)
|
||||||
val analysisResult = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(this))
|
val resolutionFacade = KotlinCacheService.getInstance(project).getResolutionFacade(filesToAnalyze + createFlexibleTypesFile())
|
||||||
|
val analysisResult = resolutionFacade.analyzeFullyAndGetResult(filesToAnalyze)
|
||||||
|
|
||||||
if (analysisResult.isError()) {
|
if (analysisResult.isError()) {
|
||||||
throw EvaluateExceptionUtil.createEvaluateException(analysisResult.error)
|
throw EvaluateExceptionUtil.createEvaluateException(analysisResult.error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ LineBreakpoint created at inlineFunction.kt:7
|
|||||||
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
inlineFunction.kt:7
|
inlineFunction.kt:7
|
||||||
Compile bytecode for myFun { 1 }
|
Compile bytecode for myFun { 1 }
|
||||||
|
Compile bytecode for foo()
|
||||||
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
|
|
||||||
Process finished with exit code 0
|
Process finished with exit code 0
|
||||||
|
|||||||
+5
@@ -7,5 +7,10 @@ fun main(args: Array<String>) {
|
|||||||
val a = 1
|
val a = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun foo() = 1
|
||||||
|
|
||||||
// EXPRESSION: myFun { 1 }
|
// EXPRESSION: myFun { 1 }
|
||||||
// RESULT: 1: I
|
// RESULT: 1: I
|
||||||
|
|
||||||
|
// EXPRESSION: foo()
|
||||||
|
// RESULT: 1: I
|
||||||
@@ -35,6 +35,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
|||||||
import com.intellij.testFramework.EdtTestUtil;
|
import com.intellij.testFramework.EdtTestUtil;
|
||||||
import com.intellij.testFramework.IdeaTestUtil;
|
import com.intellij.testFramework.IdeaTestUtil;
|
||||||
import com.intellij.util.ThrowableRunnable;
|
import com.intellij.util.ThrowableRunnable;
|
||||||
|
import com.intellij.util.indexing.FileBasedIndex;
|
||||||
import com.intellij.xdebugger.XDebugSession;
|
import com.intellij.xdebugger.XDebugSession;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage;
|
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage;
|
||||||
@@ -220,8 +221,9 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
|
|
||||||
@SuppressWarnings("MethodMayBeStatic")
|
@SuppressWarnings("MethodMayBeStatic")
|
||||||
protected void createDebugProcess(@NotNull String path) throws Exception {
|
protected void createDebugProcess(@NotNull String path) throws Exception {
|
||||||
VfsUtil.markDirty(true, true, VfsUtil.findFileByIoFile(new File(TINY_APP), true));
|
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
FileBasedIndex.getInstance().requestReindex(VfsUtil.findFileByIoFile(file, true));
|
||||||
String packageName = file.getName().replace(".kt", "");
|
String packageName = file.getName().replace(".kt", "");
|
||||||
FqName packageFQN = new FqName(packageName);
|
FqName packageFQN = new FqName(packageName);
|
||||||
String mainClassName = PackagePartClassUtils.getPackagePartFqName(packageFQN, file.getName()).asString();
|
String mainClassName = PackagePartClassUtils.getPackagePartFqName(packageFQN, file.getName()).asString();
|
||||||
|
|||||||
Reference in New Issue
Block a user