JVM_IR: Prevent writing output after an error is reported
#KT-53825 Fixed
This commit is contained in:
committed by
Alexander Udalov
parent
252e97663b
commit
7b3ce35613
+1
-1
@@ -147,7 +147,7 @@ object FirKotlinToJvmBytecodeCompiler {
|
|||||||
findMainClass(outputs.single().first.fir)
|
findMainClass(outputs.single().first.fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeOutputs(
|
return writeOutputsIfNeeded(
|
||||||
project,
|
project,
|
||||||
projectConfiguration,
|
projectConfiguration,
|
||||||
chunk,
|
chunk,
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
outputs += runCodegen(input, input.state, codegenFactory, result.bindingContext, diagnosticsReporter, environment.configuration)
|
outputs += runCodegen(input, input.state, codegenFactory, result.bindingContext, diagnosticsReporter, environment.configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeOutputs(environment.project, projectConfiguration, chunk, outputs, mainClassFqName)
|
return writeOutputsIfNeeded(environment.project, projectConfiguration, chunk, outputs, mainClassFqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun compileBunchOfSources(environment: KotlinCoreEnvironment): Boolean {
|
fun compileBunchOfSources(environment: KotlinCoreEnvironment): Boolean {
|
||||||
|
|||||||
@@ -122,13 +122,17 @@ fun writeOutput(
|
|||||||
outputFiles.writeAll(outputDir, messageCollector, reportOutputFiles)
|
outputFiles.writeAll(outputDir, messageCollector, reportOutputFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun writeOutputs(
|
fun writeOutputsIfNeeded(
|
||||||
project: Project?,
|
project: Project?,
|
||||||
projectConfiguration: CompilerConfiguration,
|
projectConfiguration: CompilerConfiguration,
|
||||||
chunk: List<Module>,
|
chunk: List<Module>,
|
||||||
outputs: List<GenerationState>,
|
outputs: List<GenerationState>,
|
||||||
mainClassFqName: FqName?
|
mainClassFqName: FqName?
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
if (projectConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).hasErrors()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (state in outputs) {
|
for (state in outputs) {
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||||
|
|||||||
+4
-1
@@ -306,11 +306,14 @@ open class JvmIrCodegenFactory(
|
|||||||
override fun invokeCodegen(input: CodegenFactory.CodegenInput) {
|
override fun invokeCodegen(input: CodegenFactory.CodegenInput) {
|
||||||
val (state, context, module, notifyCodegenStart) = input as JvmIrCodegenInput
|
val (state, context, module, notifyCodegenStart) = input as JvmIrCodegenInput
|
||||||
|
|
||||||
if ((state.diagnosticReporter as? BaseDiagnosticsCollector)?.hasErrors == true) return
|
fun hasErrors() = (state.diagnosticReporter as? BaseDiagnosticsCollector)?.hasErrors == true
|
||||||
|
|
||||||
|
if (hasErrors()) return
|
||||||
|
|
||||||
notifyCodegenStart()
|
notifyCodegenStart()
|
||||||
jvmCodegenPhases.invokeToplevel(PhaseConfig(jvmCodegenPhases), context, module)
|
jvmCodegenPhases.invokeToplevel(PhaseConfig(jvmCodegenPhases), context, module)
|
||||||
|
|
||||||
|
if (hasErrors()) return
|
||||||
// TODO: split classes into groups connected by inline calls; call this after every group
|
// TODO: split classes into groups connected by inline calls; call this after every group
|
||||||
// and clear `JvmBackendContext.classCodegens`
|
// and clear `JvmBackendContext.classCodegens`
|
||||||
state.afterIndependentPart()
|
state.afterIndependentPart()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
|
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
|
||||||
-Xuse-k2
|
|
||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
warning: ATTENTION!
|
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:3:9: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
This build uses experimental K2 compiler:
|
|
||||||
-Xuse-k2
|
|
||||||
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:2:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
|
||||||
fun `<get-x>`(): Int defined in Foo
|
fun `<get-x>`(): Int defined in Foo
|
||||||
fun getX(): Int defined in Foo
|
fun getX(): Int defined in Foo
|
||||||
fun getY(): Int defined in Foo
|
fun getY(): Int defined in Foo
|
||||||
val x: Int
|
get() = 42
|
||||||
^
|
^
|
||||||
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:8:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:8:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
fun `<get-x>`(): Int defined in Foo
|
fun `<get-x>`(): Int defined in Foo
|
||||||
fun getX(): Int defined in Foo
|
fun getX(): Int defined in Foo
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// ABSENT: Foo.class
|
||||||
|
// ABSENT: META-INF/main.kotlin_module
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
|
||||||
|
-Xuse-k2
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
warning: ATTENTION!
|
||||||
|
This build uses experimental K2 compiler:
|
||||||
|
-Xuse-k2
|
||||||
|
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:2:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
|
fun `<get-x>`(): Int defined in Foo
|
||||||
|
fun getX(): Int defined in Foo
|
||||||
|
fun getY(): Int defined in Foo
|
||||||
|
val x: Int
|
||||||
|
^
|
||||||
|
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:8:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
|
fun `<get-x>`(): Int defined in Foo
|
||||||
|
fun getX(): Int defined in Foo
|
||||||
|
fun getY(): Int defined in Foo
|
||||||
|
@JvmName("getX")
|
||||||
|
^
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// ABSENT: Foo.class
|
||||||
|
// ABSENT: META-INF/main.kotlin_module
|
||||||
Vendored
-1
@@ -1,5 +1,4 @@
|
|||||||
ERR:
|
ERR:
|
||||||
error: error while writing [Temp]/noPermissionDir/Test.class (Permission denied)
|
error: error while writing [Temp]/noPermissionDir/Test.class (Permission denied)
|
||||||
error: error while writing [Temp]/noPermissionDir/META-INF/main.kotlin_module (Permission denied)
|
|
||||||
|
|
||||||
Return code: 1
|
Return code: 1
|
||||||
|
|||||||
@@ -242,6 +242,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/conflictingJvmDeclarations.args");
|
runTest("compiler/testData/cli/jvm/conflictingJvmDeclarations.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("conflictingJvmDeclarationsK2.args")
|
||||||
|
public void testConflictingJvmDeclarationsK2() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/conflictingJvmDeclarationsK2.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("conflictingOverloads.args")
|
@TestMetadata("conflictingOverloads.args")
|
||||||
public void testConflictingOverloads() throws Exception {
|
public void testConflictingOverloads() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/conflictingOverloads.args");
|
runTest("compiler/testData/cli/jvm/conflictingOverloads.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user