Opt-in: forbid/deprecate constructor call with default arguments under marker

#KT-55074 Fixed
This commit is contained in:
Mikhail Glukhikh
2022-11-21 15:35:25 +01:00
committed by Space Team
parent b92ce68f32
commit 8ddc535caf
5 changed files with 54 additions and 29 deletions
@@ -0,0 +1,26 @@
@RequiresOptIn
annotation class Marker
@Marker
class Some(val x: Int)
class Other(val x: Int) {
@OptIn(Marker::class)
constructor(some: Some): this(some.x)
@Marker
constructor(): this(42)
@OptIn(Marker::class)
constructor(y: Long, some: Some? = null): this(some?.x ?: y.toInt())
}
fun foo(some: <!OPT_IN_USAGE_ERROR!>Some<!>? = null) {}
fun test() {
val o1 = <!OPT_IN_USAGE_ERROR!>Other<!>()
val o2 = <!OPT_IN_USAGE_ERROR!>Other<!>(<!OPT_IN_USAGE_ERROR!>Some<!>(0))
val o3 = <!OPT_IN_USAGE_ERROR!>Other<!>(444L)
<!OPT_IN_USAGE_ERROR!>foo<!>()
<!OPT_IN_USAGE_ERROR!>foo<!>(null)
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
@RequiresOptIn
annotation class Marker
@@ -16,8 +15,12 @@ class Other(val x: Int) {
constructor(y: Long, some: Some? = null): this(some?.x ?: y.toInt())
}
fun foo(some: <!OPT_IN_USAGE_ERROR!>Some<!>? = null) {}
fun test() {
val o1 = <!OPT_IN_USAGE_ERROR!>Other<!>()
val o2 = Other(<!OPT_IN_USAGE_ERROR!>Some<!>(0))
val o3 = Other(444L)
val o2 = <!OPT_IN_USAGE_FUTURE_ERROR!>Other<!>(<!OPT_IN_USAGE_ERROR!>Some<!>(0))
val o3 = <!OPT_IN_USAGE_FUTURE_ERROR!>Other<!>(444L)
<!OPT_IN_USAGE_ERROR!>foo<!>()
<!OPT_IN_USAGE_ERROR!>foo<!>(null)
}
@@ -1,5 +1,6 @@
package
public fun foo(/*0*/ some: Some? = ...): kotlin.Unit
public fun test(): kotlin.Unit
@kotlin.RequiresOptIn public final annotation class Marker : kotlin.Annotation {