[stdlib] Make @LowPriorityInOverloadResolution applicable to ctors

This commit is contained in:
Sergej Jaskiewicz
2021-12-01 16:21:41 +03:00
committed by Space
parent 2aa1c187d9
commit 599f705842
5 changed files with 36 additions and 1 deletions
@@ -461,6 +461,7 @@ internal object CheckLowPriorityInOverloadResolution : CheckerStage() {
val annotations = when (val fir = candidate.symbol.fir) {
is FirSimpleFunction -> fir.annotations
is FirProperty -> fir.annotations
is FirConstructor -> fir.annotations
else -> return
}
@@ -12,8 +12,20 @@ fun bar(a: String?) = 3
fun bar(a: Any) = 4
class MyString(val value: String)
class Baz
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
constructor(val s: String) {
constructor(s: MyString): this(s.value)
}
fun Baz(s: String) = Baz(MyString(s + "!"))
fun box(): String {
if (foo(1) != 2) return "fail1"
if (bar(null) != 3) return "fail2"
if (Baz("hello").s != "hello!") return "fail3"
return "OK"
}
@@ -14,3 +14,14 @@ class Scope {
fun Scope.bar(e: Foo) {
e.test {}
}
class Baz
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
constructor(val x: Foo)
fun Baz(x: Foo): Baz {
throw NotImplementedError()
}
fun testBaz(e: Foo) = Baz(e)
@@ -1,5 +1,7 @@
package
public fun Baz(/*0*/ x: Foo): Baz
public fun testBaz(/*0*/ e: Foo): Baz
public fun Scope.bar(/*0*/ e: Foo): kotlin.Unit
public fun Foo.test(): kotlin.Unit
@@ -10,6 +12,14 @@ public final class Bar {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Baz {
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) @kotlin.internal.LowPriorityInOverloadResolution public constructor Baz(/*0*/ x: Foo)
public final val x: Foo
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo {
public constructor Foo()
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) @kotlin.internal.LowPriorityInOverloadResolution public final val test: Bar
@@ -25,3 +35,4 @@ public final class Scope {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final operator fun Bar.invoke(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
}
@@ -22,7 +22,7 @@ internal annotation class Exact
/**
* Specifies that a corresponding member has the lowest priority in overload resolution.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.BINARY)
internal annotation class LowPriorityInOverloadResolution