AA: handle underscore as type arguments
^KTIJ-24742 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
d73d3c46e2
commit
5455942859
+4
-4
@@ -49,19 +49,19 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
get() = withValidityAssertion { analysisSession.typeProvider.builtinTypes }
|
||||
|
||||
/**
|
||||
* Approximates [KtType] with the a supertype which can be rendered in a source code
|
||||
* Approximates [KtType] with a supertype which can be rendered in a source code
|
||||
*
|
||||
* Return `null` if the type do not need approximation and can be rendered as is
|
||||
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is denotable
|
||||
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every type argument is denotable
|
||||
*/
|
||||
public fun KtType.approximateToSuperPublicDenotable(approximateLocalTypes: Boolean): KtType? =
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSuperPublicDenotableType(this, approximateLocalTypes) }
|
||||
|
||||
/**
|
||||
* Approximates [KtType] with the a subtype which can be rendered in a source code
|
||||
* Approximates [KtType] with a subtype which can be rendered in a source code
|
||||
*
|
||||
* Return `null` if the type do not need approximation and can be rendered as is
|
||||
* Otherwise, for type `T` return type `S` such `S <: T` and `T` and every it type argument is denotable
|
||||
* Otherwise, for type `T` return type `S` such `S <: T` and `T` and every type argument is denotable
|
||||
*/
|
||||
public fun KtType.approximateToSubPublicDenotable(approximateLocalTypes: Boolean): KtType? =
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSubPublicDenotableType(this, approximateLocalTypes) }
|
||||
|
||||
+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