[JS IR] Fix clash between generic extension overloads
Type parameter constraints are used for calculating JS signature hash. ^KT-51151 Fixed
This commit is contained in:
committed by
Space
parent
9f5cbea0fa
commit
0982872959
@@ -0,0 +1,42 @@
|
||||
class Receiver()
|
||||
|
||||
class Scope() {
|
||||
fun <T : String> Receiver.testOverload(e: T) = "String"
|
||||
fun <T : CharSequence> Receiver.testOverload(e: T) = "CharSequence"
|
||||
fun <T : Any> Receiver.testOverload(e: T) = "Any"
|
||||
}
|
||||
|
||||
class NullableScope() {
|
||||
fun <T : String?> Receiver.testOverload(e: T) = "String?"
|
||||
fun <T : String> Receiver.testOverload(e: T) = "String"
|
||||
fun <T : CharSequence> Receiver.testOverload(e: T) = "CharSequence"
|
||||
fun <T : Any?> Receiver.testOverload(e: T) = "Any?"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val stringVal: String = "Stirng value"
|
||||
val charSequenceVal: CharSequence = "CharSequence value"
|
||||
val anyVal: Any = "Any value"
|
||||
|
||||
val r = Receiver()
|
||||
|
||||
Scope().apply {
|
||||
assertEquals("String", r.testOverload(stringVal))
|
||||
assertEquals("CharSequence", r.testOverload(charSequenceVal))
|
||||
assertEquals("Any", r.testOverload(anyVal))
|
||||
}
|
||||
|
||||
val stringOrNullVal: String? = "Stirng? value"
|
||||
val charSequenceOrNullVal: CharSequence? = "CharSequence? value"
|
||||
val anyOrNullVal: Any? = "Any? value"
|
||||
|
||||
NullableScope().apply {
|
||||
assertEquals("String", r.testOverload(stringVal))
|
||||
assertEquals("String?", r.testOverload(stringOrNullVal))
|
||||
assertEquals("CharSequence", r.testOverload(charSequenceVal))
|
||||
assertEquals("Any?", r.testOverload(charSequenceOrNullVal))
|
||||
assertEquals("Any?", r.testOverload(anyVal))
|
||||
assertEquals("Any?", r.testOverload(anyOrNullVal))
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
class Receiver()
|
||||
|
||||
open class A1
|
||||
|
||||
open class A2: A1()
|
||||
|
||||
open class A3: A2()
|
||||
|
||||
class GenericScope<E : A1>() {
|
||||
class GenericSubScope<E : A2> {
|
||||
fun <T : E> Receiver.testOverload(e: T) = "SubScope"
|
||||
}
|
||||
fun <T : E> Receiver.testOverload(e: T) = "Scope"
|
||||
}
|
||||
|
||||
class GenericScopeWithOverloads<E : A1>() {
|
||||
class GenericSubScopeWithOverloads<E : A2> {
|
||||
fun <T : E> Receiver.testOverload(e: T) = "SubScope"
|
||||
fun <T : A3> Receiver.testOverload(e: T) = "SubScope A3"
|
||||
}
|
||||
fun <T : E> Receiver.testOverload(e: T) = "Scope"
|
||||
fun <T : A2> Receiver.testOverload(e: T) = "Scope A2"
|
||||
fun <T : A3> Receiver.testOverload(e: T) = "Scope A3"
|
||||
}
|
||||
|
||||
val r = Receiver()
|
||||
|
||||
fun testGenericScope() {
|
||||
GenericScope<A1>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("Scope", r.testOverload(A2()))
|
||||
assertEquals("Scope", r.testOverload(A3()))
|
||||
|
||||
GenericScope.GenericSubScope<A2>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("SubScope", r.testOverload(A2()))
|
||||
assertEquals("SubScope", r.testOverload(A3()))
|
||||
}
|
||||
|
||||
GenericScope.GenericSubScope<A3>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("Scope", r.testOverload(A2()))
|
||||
assertEquals("SubScope", r.testOverload(A3()))
|
||||
}
|
||||
}
|
||||
|
||||
GenericScope<A2>().apply {
|
||||
assertEquals("Scope", r.testOverload(A2()))
|
||||
assertEquals("Scope", r.testOverload(A3()))
|
||||
|
||||
GenericScope.GenericSubScope<A2>().apply {
|
||||
assertEquals("SubScope", r.testOverload(A2()))
|
||||
assertEquals("SubScope", r.testOverload(A3()))
|
||||
}
|
||||
|
||||
GenericScope.GenericSubScope<A3>().apply {
|
||||
assertEquals("Scope", r.testOverload(A2()))
|
||||
assertEquals("SubScope", r.testOverload(A3()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testGenericScopeWithOverloads() {
|
||||
GenericScopeWithOverloads<A1>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("Scope A2", r.testOverload(A2()))
|
||||
assertEquals("Scope A3", r.testOverload(A3()))
|
||||
|
||||
GenericScopeWithOverloads.GenericSubScopeWithOverloads<A2>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("SubScope", r.testOverload(A2()))
|
||||
assertEquals("SubScope A3", r.testOverload(A3()))
|
||||
}
|
||||
|
||||
GenericScopeWithOverloads.GenericSubScopeWithOverloads<A3>().apply {
|
||||
assertEquals("Scope", r.testOverload(A1()))
|
||||
assertEquals("Scope A2", r.testOverload(A2()))
|
||||
}
|
||||
}
|
||||
|
||||
GenericScopeWithOverloads<A2>().apply {
|
||||
assertEquals("Scope A3", r.testOverload(A3()))
|
||||
|
||||
GenericScopeWithOverloads.GenericSubScopeWithOverloads<A2>().apply {
|
||||
assertEquals("SubScope", r.testOverload(A2()))
|
||||
assertEquals("SubScope A3", r.testOverload(A3()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testGenericScope()
|
||||
testGenericScopeWithOverloads()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user