KTIJ-27050 [Analysis API] Correctly handle type parameters in KtFirReferenceShortener

Make `FirShorteningContext` correctly return symbols for type
parameters, so they are not ignored when scopes are inspected

Add additional type of `PartialOrderOfScope` - `TypeParameter`, because
otherwise it would have been classified as `Unclassified`, and that
breaks scopes comparison

Add missing type parameters to the scope of class header in
`ContextCollector`, add testdata for that

There is a bug in the compiler with type parameters leaking to nested
classes headers (KT-61959). After it's fixed, the testData with
incorrect expected shortenings/scopes should be adjusted and fixed too

^KTIJ-27050 Fixed
This commit is contained in:
Roman Golyshev
2023-09-14 17:06:15 +02:00
committed by teamcity
parent e2019ceb95
commit a78d631b16
29 changed files with 560 additions and 12 deletions
@@ -0,0 +1,10 @@
package test
interface MyType
<expr>
context(test.MyType)
fun <MyType> test.MyType.test(p: test.MyType) {
val a: test.MyType
}
</expr>
@@ -0,0 +1,8 @@
Before shortening: context(test.MyType)
fun <MyType> test.MyType.test(p: test.MyType) {
val a: test.MyType
}
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,14 @@
package test
open class Base<T>()
class MyClass<MyType> {
interface MyType
<expr>
context(MyClass.MyType)
class Nested<Other : MyClass.MyType> : Base<MyClass.MyType>()
</expr>
}
@@ -0,0 +1,15 @@
Before shortening: context(MyClass.MyType)
class Nested<Other : MyClass.MyType> : Base<MyClass.MyType>()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] MyClass.MyType
[type] MyClass.MyType
[type] MyClass.MyType
with SHORTEN_AND_IMPORT:
[type] MyClass.MyType
[type] MyClass.MyType
[type] MyClass.MyType
with SHORTEN_AND_STAR_IMPORT:
[type] MyClass.MyType
[type] MyClass.MyType
[type] MyClass.MyType
@@ -0,0 +1,10 @@
package test
interface MyType
open class Base<T>()
<expr>
context(test.MyType)
class MyClass<MyType, Other : test.MyType> : Base<test.MyType>()
</expr>
@@ -0,0 +1,6 @@
Before shortening: context(test.MyType)
class MyClass<MyType, Other : test.MyType> : Base<test.MyType>()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,13 @@
package test
interface MyType
open class Base<T>()
class MyClass<MyType> {
// TODO this test has an error, MyType should not be resolved here. See KT-61959
<expr>
context(test.MyType)
class Nested<Other : test.MyType> : Base<test.MyType>()
</expr>
}
@@ -0,0 +1,6 @@
Before shortening: context(test.MyType)
class Nested<Other : test.MyType> : Base<test.MyType>()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT: