Do not continue compilation if collected dependencies contain error
avoids additional errors reported by compilation, if configuration refinement returned error
This commit is contained in:
+2
@@ -120,6 +120,8 @@ private fun compileImpl(
|
||||
messageCollector
|
||||
)
|
||||
|
||||
if (sourceDependencies.any { it.sourceDependencies is ResultWithDiagnostics.Failure }) return failure(messageCollector)
|
||||
|
||||
val dependenciesProvider = ScriptDependenciesProvider.getInstance(context.environment.project)
|
||||
val getScriptConfiguration = { ktFile: KtFile ->
|
||||
(dependenciesProvider?.getScriptConfiguration(ktFile)?.configuration ?: context.baseScriptCompilationConfiguration)
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.scripting.compiler.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||
|
||||
class ScriptCompilerTest : TestCase() {
|
||||
|
||||
fun testCompilationWithRefinementError() {
|
||||
val res = compile("nonsense".toScriptSource()) {
|
||||
refineConfiguration {
|
||||
beforeCompiling {
|
||||
ResultWithDiagnostics.Failure("err13".asErrorDiagnostics())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(res is ResultWithDiagnostics.Failure)
|
||||
assertTrue(res.reports.any { it.message == "err13" })
|
||||
assertTrue(res.reports.none { it.message.contains("nonsense") })
|
||||
}
|
||||
|
||||
fun compile(
|
||||
script: SourceCode,
|
||||
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
||||
): ResultWithDiagnostics<CompiledScript> {
|
||||
val compilationConfiguration = ScriptCompilationConfiguration(cfgBody)
|
||||
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
||||
return compiler.compile(script, compilationConfiguration)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user