AA: handle underscore as type arguments
^KTIJ-24742 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
d73d3c46e2
commit
5455942859
+12
@@ -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")
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: Base<*>
|
||||
ktType: Base<*>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
open class Base
|
||||
|
||||
class Sub : Bas<caret>e()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: Base
|
||||
ktType: Base
|
||||
+7
@@ -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"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: Base<String>
|
||||
ktType: Base<kotlin.String>
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
inline fun <T> foo(arg: T) {
|
||||
println(arg.toString())
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo<Strin<caret>g>("42")
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: String
|
||||
ktType: kotlin.String
|
||||
Vendored
+7
@@ -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"
|
||||
}
|
||||
analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.txt
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: String
|
||||
ktType: kotlin.String
|
||||
+32
@@ -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)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: _
|
||||
ktType: kotlin.Int
|
||||
+32
@@ -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)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: _
|
||||
ktType: OtherImplementation
|
||||
Reference in New Issue
Block a user