File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
kotlin-extractor/src/main/kotlin
ql/integration-tests/all-platforms/kotlin/jvmoverloads-external-class Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1095,7 +1095,14 @@ open class KotlinFileExtractor(
10951095 }
10961096
10971097 if (! f.hasAnnotation(jvmOverloadsFqName)) {
1098- if (f is IrConstructor && f.valueParameters.isNotEmpty() && f.valueParameters.all { it.defaultValue != null }) {
1098+ if (f is IrConstructor &&
1099+ f.valueParameters.isNotEmpty() &&
1100+ f.valueParameters.all { it.defaultValue != null } &&
1101+ f.parentClassOrNull?.let {
1102+ // Don't create a default constructor for an annotation class, or a class that explicitly declares a no-arg constructor.
1103+ ! it.isAnnotationClass &&
1104+ it.declarations.none { d -> d is IrConstructor && d.valueParameters.isEmpty() }
1105+ } == true ) {
10991106 // Per https://kotlinlang.org/docs/classes.html#creating-instances-of-classes, a single default overload gets created specifically
11001107 // when we have all default parameters, regardless of `@JvmOverloads`.
11011108 extractGeneratedOverload(f.valueParameters.map { _ -> null })
Original file line number Diff line number Diff line change 1+ @ AllDefaultsAnnotation
12public class User {
23
3- public static void test () { new AllDefaultsConstructor (); }
4+ public static void test () { new AllDefaultsConstructor (); new AllDefaultsExplicitNoargConstructor (); }
45
56}
Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ public class Test {
55}
66
77public class AllDefaultsConstructor (val x : Int = 1 , val y : Int = 2 ) { }
8+
9+ public annotation class AllDefaultsAnnotation (val x : Int = 1 , val y : Int = 2 ) { }
10+
11+ public class AllDefaultsExplicitNoargConstructor (val x : Int = 1 , val y : Int = 2 ) {
12+
13+ constructor () : this (3 , 4 ) { }
14+
15+ }
You can’t perform that action at this time.
0 commit comments