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)
|
||||
}
|
||||
|
||||
return writeOutputs(
|
||||
return writeOutputsIfNeeded(
|
||||
project,
|
||||
projectConfiguration,
|
||||
chunk,
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
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 {
|
||||
|
||||
@@ -122,13 +122,17 @@ fun writeOutput(
|
||||
outputFiles.writeAll(outputDir, messageCollector, reportOutputFiles)
|
||||
}
|
||||
|
||||
fun writeOutputs(
|
||||
fun writeOutputsIfNeeded(
|
||||
project: Project?,
|
||||
projectConfiguration: CompilerConfiguration,
|
||||
chunk: List<Module>,
|
||||
outputs: List<GenerationState>,
|
||||
mainClassFqName: FqName?
|
||||
): Boolean {
|
||||
if (projectConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).hasErrors()) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
for (state in outputs) {
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
|
||||
+4
-1
@@ -306,11 +306,14 @@ open class JvmIrCodegenFactory(
|
||||
override fun invokeCodegen(input: CodegenFactory.CodegenInput) {
|
||||
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()
|
||||
jvmCodegenPhases.invokeToplevel(PhaseConfig(jvmCodegenPhases), context, module)
|
||||
|
||||
if (hasErrors()) return
|
||||
// TODO: split classes into groups connected by inline calls; call this after every group
|
||||
// and clear `JvmBackendContext.classCodegens`
|
||||
state.afterIndependentPart()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
|
||||
-Xuse-k2
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
@@ -1,12 +1,9 @@
|
||||
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):
|
||||
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:3:9: 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
|
||||
^
|
||||
get() = 42
|
||||
^
|
||||
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
|
||||
|
||||
@@ -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:
|
||||
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
|
||||
|
||||
@@ -242,6 +242,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
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")
|
||||
public void testConflictingOverloads() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/conflictingOverloads.args");
|
||||
|
||||
Reference in New Issue
Block a user