only stub default constructor when compiling against .java source files

This commit is contained in:
Kevin Bierhoff
2020-03-09 11:33:20 -07:00
committed by Alexander Udalov
parent c83860187c
commit 7448761dfd
19 changed files with 90 additions and 2 deletions
@@ -458,6 +458,37 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
}
}
/* Regression test for KT-37107: compile against .class file without any constructors. */
fun testClassfileWithoutConstructors() {
compileKotlin("TopLevel.kt", tmpdir, expectedFileName = "TopLevel.txt")
val inlineFunClass = File(tmpdir.absolutePath, "test/TopLevelKt.class")
val cw = ClassWriter(Opcodes.API_VERSION)
ClassReader(inlineFunClass.readBytes()).accept(object : ClassVisitor(Opcodes.API_VERSION, cw) {
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? =
if (desc == JvmAnnotationNames.METADATA_DESC) null else super.visitAnnotation(desc, visible)
override fun visitMethod(
access: Int,
name: String?,
descriptor: String?,
signature: String?,
exceptions: Array<out String>?
): MethodVisitor {
assertEquals("foo", name) // test sanity: shouldn't see any constructors, only the "foo" method
return super.visitMethod(access, name, descriptor, signature, exceptions)
}
}, 0)
assert(inlineFunClass.delete())
assert(!inlineFunClass.exists())
inlineFunClass.writeBytes(cw.toByteArray())
val (_, exitCode) = compileKotlin("shouldNotCompile.kt", tmpdir, listOf(tmpdir))
assertEquals(1, exitCode.code) // double-check that we failed :) output.txt also says so
}
fun testReplaceAnnotationClassWithInterface() {
val library1 = compileLibrary("library-1")
val usage = compileLibrary("usage", extraClassPath = listOf(library1))
@@ -70,6 +70,11 @@ public class CompileKotlinAgainstJavaTestGenerated extends AbstractCompileKotlin
runTest("compiler/testData/compileKotlinAgainstJava/Class.kt");
}
@TestMetadata("ClassDefaultConstructor.kt")
public void testClassDefaultConstructor() throws Exception {
runTest("compiler/testData/compileKotlinAgainstJava/ClassDefaultConstructor.kt");
}
@TestMetadata("ClassWithNestedEnum.kt")
public void testClassWithNestedEnum() throws Exception {
runTest("compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt");
@@ -353,6 +358,11 @@ public class CompileKotlinAgainstJavaTestGenerated extends AbstractCompileKotlin
runTest("compiler/testData/compileKotlinAgainstJava/Class.kt");
}
@TestMetadata("ClassDefaultConstructor.kt")
public void testClassDefaultConstructor() throws Exception {
runTest("compiler/testData/compileKotlinAgainstJava/ClassDefaultConstructor.kt");
}
@TestMetadata("ClassWithNestedEnum.kt")
public void testClassWithNestedEnum() throws Exception {
runTest("compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt");