Fix no-arg constructor generation for actual class
This commit is contained in:
+1
-1
@@ -256,7 +256,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
||||
if (constructorDescriptor.valueParameters.isEmpty()) return false
|
||||
if (classOrObject is KtClass && hasSecondaryConstructorsWithNoParameters(classOrObject)) return false
|
||||
|
||||
return constructorDescriptor.valueParameters.all { it.declaresDefaultValue() }
|
||||
return constructorDescriptor.valueParameters.all { it.hasDefaultValue() }
|
||||
}
|
||||
|
||||
private fun hasSecondaryConstructorsWithNoParameters(klass: KtClass) =
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo(a: String = "", b: Int = 42)
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public static void test() {
|
||||
new Foo();
|
||||
new Foo("", 42);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: jvm.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
actual class Foo actual constructor(a: String, b: Int) {
|
||||
init {
|
||||
assertEquals("", a)
|
||||
assertEquals(42, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
J.test()
|
||||
return "OK"
|
||||
}
|
||||
Generated
+5
@@ -13236,6 +13236,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("noArgActualConstructor.kt")
|
||||
public void testNoArgActualConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/noArgActualConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+5
@@ -13236,6 +13236,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("noArgActualConstructor.kt")
|
||||
public void testNoArgActualConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/noArgActualConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+5
@@ -13236,6 +13236,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("noArgActualConstructor.kt")
|
||||
public void testNoArgActualConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/noArgActualConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+13
@@ -48,4 +48,17 @@ public class OutputPrefixPostfixTestGenerated extends AbstractOutputPrefixPostfi
|
||||
public void testSimpleWithPrefixAndPostfix() throws Exception {
|
||||
runTest("js/js.translator/testData/outputPrefixPostfix/simpleWithPrefixAndPostfix.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/outputPrefixPostfix/out")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Out extends AbstractOutputPrefixPostfixTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInOut() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/outputPrefixPostfix/out"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+13
@@ -43,4 +43,17 @@ public class SourceMapGenerationSmokeTestGenerated extends AbstractSourceMapGene
|
||||
public void testMethodCallInMethod() throws Exception {
|
||||
runTest("js/js.translator/testData/sourcemap/methodCallInMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/sourcemap/out")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Out extends AbstractSourceMapGenerationSmokeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInOut() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/sourcemap/out"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user