AA: handle underscore as type arguments

^KTIJ-24742 Fixed
This commit is contained in:
Jinseong Jeon
2023-02-21 17:40:32 -08:00
committed by Ilya Kirillov
parent d73d3c46e2
commit 5455942859
23 changed files with 537 additions and 7 deletions
@@ -0,0 +1,12 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : Base<String> {
override fun foo(arg: String) = arg + " = 42"
}
fun test() {
val x : Base<<caret>*> = StringSub()
x.foo("42")
}
@@ -0,0 +1,2 @@
expression: Base<*>
ktType: Base<*>
@@ -0,0 +1,3 @@
open class Base
class Sub : Bas<caret>e()
@@ -0,0 +1,2 @@
expression: Base
ktType: Base
@@ -0,0 +1,7 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : B<caret>ase<String> {
override fun foo(arg: String) = arg + " = 42"
}
@@ -0,0 +1,2 @@
expression: Base<String>
ktType: Base<kotlin.String>
@@ -0,0 +1,7 @@
inline fun <T> foo(arg: T) {
println(arg.toString())
}
fun test() {
foo<Strin<caret>g>("42")
}
@@ -0,0 +1,2 @@
expression: String
ktType: kotlin.String
@@ -0,0 +1,7 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : Base<Strin<caret>g> {
override fun foo(arg: String) = arg + " = 42"
}
@@ -0,0 +1,2 @@
expression: String
ktType: kotlin.String
@@ -0,0 +1,32 @@
// example from https://kotlinlang.org/docs/generics.html#underscore-operator-for-type-arguments
// modified to avoid using reflection (::class.java)
abstract class SomeClass<T> {
abstract fun execute() : T
}
class SomeImplementation : SomeClass<String>() {
override fun execute(): String = "Test"
}
class OtherImplementation : SomeClass<Int>() {
override fun execute(): Int = 42
}
object Runner {
inline fun <reified S: SomeClass<T>, T> run(instance: S) : T {
return instance.execute()
}
}
fun test() {
val i = SomeImplementation()
// T is inferred as String because SomeImplementation derives from SomeClass<String>
val s = Runner.run<_, _>(i)
assert(s == "Test")
val j = OtherImplementation()
// T is inferred as Int because OtherImplementation derives from SomeClass<Int>
val n = Runner.run<_, <caret>_>(j)
assert(n == 42)
}
@@ -0,0 +1,2 @@
expression: _
ktType: kotlin.Int
@@ -0,0 +1,32 @@
// example from https://kotlinlang.org/docs/generics.html#underscore-operator-for-type-arguments
// modified to avoid using reflection (::class.java)
abstract class SomeClass<T> {
abstract fun execute() : T
}
class SomeImplementation : SomeClass<String>() {
override fun execute(): String = "Test"
}
class OtherImplementation : SomeClass<Int>() {
override fun execute(): Int = 42
}
object Runner {
inline fun <reified S: SomeClass<T>, T> run(instance: S) : T {
return instance.execute()
}
}
fun test() {
val i = SomeImplementation()
// T is inferred as String because SomeImplementation derives from SomeClass<String>
val s = Runner.run<_, _>(i)
assert(s == "Test")
val j = OtherImplementation()
// T is inferred as Int because OtherImplementation derives from SomeClass<Int>
val n = Runner.run<<caret>_, _>(j)
assert(n == 42)
}
@@ -0,0 +1,2 @@
expression: _
ktType: OtherImplementation