[Analysis API] Handle missed cases in PsiElement.getExpectedType()

^KTIJ-24256
This commit is contained in:
aleksandrina-streltsova
2023-01-19 21:48:30 +02:00
committed by teamcity
parent 7dd438cb9e
commit 3d0bca5ca1
70 changed files with 1112 additions and 72 deletions
@@ -0,0 +1,3 @@
fun test() {
if (!a<caret>v)
}
@@ -0,0 +1,2 @@
expression: av
expected type: null
@@ -0,0 +1,7 @@
class A {
operator fun get(p1: Int) {}
operator fun set(p1: String, p2: Int, value: Int) {}
fun d() = this[a<caret>v]
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,8 @@
// IGNORE_FE10
class A {
operator fun <T> get(key: T) {}
}
fun test(a: A) {
a[a<caret>v]
}
@@ -0,0 +1,4 @@
expression: av
expected type: KtTypeParameterType:
annotationsList: []
type: T
@@ -0,0 +1,8 @@
class A {
operator fun get(p1: Int) {}
operator fun set(p1: String, p2: Int, value: Int) {}
fun d() {
this[a<caret>v, 2] = 1
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
@@ -0,0 +1,7 @@
class A {
operator fun <T> set(key: T, value: T) {}
}
fun test(a: A) {
a[a<caret>v] = 1
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,10 @@
enum class E {
A
B
}
fun foo(e: E) {
when(e) {
a<caret>v -> null
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: E
@@ -0,0 +1,5 @@
fun foo() {
when() {
a<caret>v -> null
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Boolean
@@ -0,0 +1,3 @@
fun foo() {
val result: Int = a<caret>v ?: 1
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int?
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int?
@@ -0,0 +1,3 @@
fun foo(i: Int?) {
val result: Int = i ?: a<caret>v
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -1,4 +0,0 @@
expression: av
expected type: KtTypeErrorType:
annotationsList: []
type: ERROR_TYPE
@@ -1,4 +1,2 @@
expression: av
expected type: KtClassErrorType:
annotationsList: []
type: ERROR_TYPE
expected type: null
@@ -0,0 +1,4 @@
expression: ab
expected type: KtTypeParameterType:
annotationsList: []
type: T
@@ -1,4 +1,5 @@
expression: ab
expected type: KtTypeParameterType:
expected type: KtUsualClassType:
annotationsList: []
type: T
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,5 @@
fun x() {
1 toCall a<caret>v
}
infix fun <T> T.toCall(y: T) {}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,2 @@
expression: av
expected type: null
@@ -0,0 +1,5 @@
// WITH_STDLIB
// IGNORE_FE10
fun foo(list: List<Int>) {
val result: List<String> = list.map { a<caret>v }
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
@@ -0,0 +1,4 @@
// WITH_STDLIB
fun foo(list: List<Int>) {
val result: List<Int> = list.map { mapOf(a<caret>v) }
}
@@ -0,0 +1,12 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtTypeParameterType:
annotationsList: []
type: K
KtTypeParameterType:
annotationsList: []
type: V
]
type: kotlin/Pair<K, V>
@@ -0,0 +1,4 @@
// WITH_STDLIB
fun foo(list: List<Int>) {
val result = list.map { a<caret>v }
}
@@ -0,0 +1,4 @@
expression: av
expected type: KtTypeParameterType:
annotationsList: []
type: R
@@ -0,0 +1,5 @@
fun foo() {
val result: Int = try {
a<caret>v
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,2 @@
expression: av
expected type: null
@@ -1,4 +0,0 @@
expression: av
expected type: KtTypeErrorType:
annotationsList: []
type: ERROR_TYPE
@@ -1,4 +1,2 @@
expression: av
expected type: KtClassErrorType:
annotationsList: []
type: ERROR_TYPE
expected type: null
@@ -0,0 +1,3 @@
fun foo() {
val result = if (true) 1 else a<caret>v
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,7 @@
fun foo() {
val result = if (true) {
1
} else {
a<caret>v
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,3 @@
fun foo() {
if (true) a<caret>v else 1
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,11 @@
enum class E {
A
B
}
fun foo(e: E) {
val result = when(e) {
E.A -> 1
E.B -> a<caret>v
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,11 @@
enum class E {
A
B
}
fun foo(e: E) {
val result = when(e) {
E.A -> { 1 }
E.B -> { a<caret>v }
}
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,13 @@
enum class E {
A
B
C
D
}
fun foo(e: E) = when (e) {
E.A -> 1
E.B -> ""
E.C -> a<caret>v
E.D -> unresolved
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
@@ -0,0 +1,8 @@
// IGNORE_FE10
class A {
operator fun <T> set(key: Int, value: T) {}
}
fun test(a: A) {
<expr>a[1]</expr> = ""
}
@@ -0,0 +1,3 @@
expression: xy
expected type: (T) -> R
functionClassKind: kotlin.FunctionN
@@ -1,3 +1,3 @@
expression: xy
expected type: (T) -> R
expected type: (kotlin.Int) -> R
functionClassKind: kotlin.FunctionN