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(
1095
1095
}
1096
1096
1097
1097
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 ) {
1099
1106
// Per https://kotlinlang.org/docs/classes.html#creating-instances-of-classes, a single default overload gets created specifically
1100
1107
// when we have all default parameters, regardless of `@JvmOverloads`.
1101
1108
extractGeneratedOverload(f.valueParameters.map { _ -> null })
Original file line number Diff line number Diff line change
1
+ @ AllDefaultsAnnotation
1
2
public class User {
2
3
3
- public static void test () { new AllDefaultsConstructor (); }
4
+ public static void test () { new AllDefaultsConstructor (); new AllDefaultsExplicitNoargConstructor (); }
4
5
5
6
}
Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ public class Test {
5
5
}
6
6
7
7
public 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