mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Don't create a default constructor for annotations, or classes that explicitly declare a no-arg constructor.
This commit is contained in:
@@ -1095,7 +1095,14 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
if (!f.hasAnnotation(jvmOverloadsFqName)) {
|
||||
if (f is IrConstructor && f.valueParameters.isNotEmpty() && f.valueParameters.all { it.defaultValue != null }) {
|
||||
if (f is IrConstructor &&
|
||||
f.valueParameters.isNotEmpty() &&
|
||||
f.valueParameters.all { it.defaultValue != null } &&
|
||||
f.parentClassOrNull?.let {
|
||||
// Don't create a default constructor for an annotation class, or a class that explicitly declares a no-arg constructor.
|
||||
!it.isAnnotationClass &&
|
||||
it.declarations.none { d -> d is IrConstructor && d.valueParameters.isEmpty() }
|
||||
} == true) {
|
||||
// Per https://kotlinlang.org/docs/classes.html#creating-instances-of-classes, a single default overload gets created specifically
|
||||
// when we have all default parameters, regardless of `@JvmOverloads`.
|
||||
extractGeneratedOverload(f.valueParameters.map { _ -> null })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@AllDefaultsAnnotation
|
||||
public class User {
|
||||
|
||||
public static void test() { new AllDefaultsConstructor(); }
|
||||
public static void test() { new AllDefaultsConstructor(); new AllDefaultsExplicitNoargConstructor(); }
|
||||
|
||||
}
|
||||
|
||||
@@ -5,3 +5,11 @@ public class Test {
|
||||
}
|
||||
|
||||
public class AllDefaultsConstructor(val x: Int = 1, val y: Int = 2) { }
|
||||
|
||||
public annotation class AllDefaultsAnnotation(val x: Int = 1, val y: Int = 2) { }
|
||||
|
||||
public class AllDefaultsExplicitNoargConstructor(val x: Int = 1, val y: Int = 2) {
|
||||
|
||||
constructor() : this(3, 4) { }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user