[FIR] Fix calculating of source of TypeArgumentList, add source to FirQualifierPart

Fix positioning for TYPE_ARGUMENTS_NOT_ALLOWED
This commit is contained in:
Ivan Kochurkin
2021-07-06 22:21:33 +03:00
committed by TeamCityServer
parent 28a6928873
commit 0c25d280ee
8 changed files with 34 additions and 19 deletions
@@ -1,14 +1,14 @@
package rest package rest
abstract class Foo<T> { abstract class Foo<T> {
abstract val x: <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Int><!> abstract val x: T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Int><!>
abstract fun foo(): <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String><!> abstract fun foo(): T<!TYPE_ARGUMENTS_NOT_ALLOWED!><String><!>
} }
fun <T> foo() { fun <T> foo() {
bar<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Int><!>>() bar<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Int><!>>()
bar<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Boolean><!>>>>() bar<List<List<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Boolean><!>>>>()
} }
fun <T> bar() {} fun <T> bar() {}
@@ -26,9 +26,9 @@ class C<F<!SYNTAX!><<!><!SYNTAX!>Boolean<!><!SYNTAX!>><!><!SYNTAX!>><!> <!SYNTAX
fun <G> gest() {} fun <G> gest() {}
fun <T> fest() { fun <T> fest() {
val b: List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Double><!>> val b: List<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Double><!>>
gest<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Char><!>>() gest<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Char><!>>()
gest<T>() gest<T>()
val c: List<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String><!>>>> val c: List<List<List<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><String><!>>>>
gest<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Boolean><!>>>>() gest<List<List<T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Boolean><!>>>>()
} }
@@ -1843,12 +1843,20 @@ class DeclarationsConverter(
): FirTypeRef { ): FirTypeRef {
var simpleFirUserType: FirUserTypeRef? = null var simpleFirUserType: FirUserTypeRef? = null
var identifier: String? = null var identifier: String? = null
var identifierSource: FirSourceElement? = null
val firTypeArguments = mutableListOf<FirTypeProjection>() val firTypeArguments = mutableListOf<FirTypeProjection>()
var typeArgumentsSource: FirSourceElement? = null
userType.forEachChildren { userType.forEachChildren {
when (it.tokenType) { when (it.tokenType) {
USER_TYPE -> simpleFirUserType = convertUserType(typeRefSource, it) as? FirUserTypeRef //simple user type USER_TYPE -> simpleFirUserType = convertUserType(typeRefSource, it) as? FirUserTypeRef //simple user type
REFERENCE_EXPRESSION -> identifier = it.asText REFERENCE_EXPRESSION -> {
TYPE_ARGUMENT_LIST -> firTypeArguments += convertTypeArguments(it) identifierSource = it.toFirSourceElement()
identifier = it.asText
}
TYPE_ARGUMENT_LIST -> {
typeArgumentsSource = it.toFirSourceElement()
firTypeArguments += convertTypeArguments(it)
}
} }
} }
@@ -1859,8 +1867,9 @@ class DeclarationsConverter(
} }
val qualifierPart = FirQualifierPartImpl( val qualifierPart = FirQualifierPartImpl(
identifierSource!!,
identifier.nameAsSafeName(), identifier.nameAsSafeName(),
FirTypeArgumentListImpl(typeRefSource).apply { FirTypeArgumentListImpl(typeArgumentsSource ?: typeRefSource).apply {
typeArguments += firTypeArguments typeArguments += firTypeArguments
} }
) )
@@ -1489,8 +1489,9 @@ open class RawFirBuilder(
do { do {
val firQualifier = FirQualifierPartImpl( val firQualifier = FirQualifierPartImpl(
referenceExpression!!.toFirSourceElement(),
referenceExpression!!.getReferencedNameAsName(), referenceExpression!!.getReferencedNameAsName(),
FirTypeArgumentListImpl(source).apply { FirTypeArgumentListImpl(ktQualifier?.typeArgumentList?.toFirPsiSourceElement() ?: source).apply {
for (typeArgument in ktQualifier!!.typeArguments) { for (typeArgument in ktQualifier!!.typeArguments) {
typeArguments += typeArgument.convert<FirTypeProjection>() typeArguments += typeArgument.convert<FirTypeProjection>()
} }
@@ -14,6 +14,7 @@ interface FirTypeArgumentList {
} }
interface FirQualifierPart { interface FirQualifierPart {
val source: FirSourceElement
val name: Name val name: Name
val typeArgumentList: FirTypeArgumentList val typeArgumentList: FirTypeArgumentList
} }
@@ -15,4 +15,8 @@ class FirTypeArgumentListImpl(override val source: FirSourceElement) : FirTypeAr
override val typeArguments = mutableListOf<FirTypeProjection>() override val typeArguments = mutableListOf<FirTypeProjection>()
} }
class FirQualifierPartImpl(override val name: Name, override val typeArgumentList: FirTypeArgumentList) : FirQualifierPart class FirQualifierPartImpl(
override val source: FirSourceElement,
override val name: Name,
override val typeArgumentList: FirTypeArgumentList
) : FirQualifierPart
@@ -12,7 +12,7 @@ package foobar.a
package foobar package foobar
abstract class Foo<T>() { abstract class Foo<T>() {
abstract val x : <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Int><!> abstract val x : T<!TYPE_ARGUMENTS_NOT_ALLOWED!><Int><!>
} }
// FILE: c.kt // FILE: c.kt
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T> foo(t: <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String, Int><!>) {} fun <T> foo(t: T<!TYPE_ARGUMENTS_NOT_ALLOWED!><String, Int><!>) {}
interface A interface A
class B<T: A> class B<T: A>
fun <T> foo1(t: <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<B<String>><!>) {} fun <T> foo1(t: T<!TYPE_ARGUMENTS_NOT_ALLOWED!><B<String>><!>) {}
@@ -1,14 +1,14 @@
// KT-9620 AssertionError in checkBounds // KT-9620 AssertionError in checkBounds
interface E1<T : <!TYPE_ARGUMENTS_NOT_ALLOWED!>D<String><!>, D> interface E1<T : D<!TYPE_ARGUMENTS_NOT_ALLOWED!><String><!>, D>
interface A interface A
interface B interface B
interface D<X> interface D<X>
interface E2<T : <!TYPE_ARGUMENTS_NOT_ALLOWED!>D<A><!>, D<!SYNTAX!><<!><!SYNTAX!>B<!><!SYNTAX!>><!><!SYNTAX!>><!> interface E2<T : D<!TYPE_ARGUMENTS_NOT_ALLOWED!><A><!>, D<!SYNTAX!><<!><!SYNTAX!>B<!><!SYNTAX!>><!><!SYNTAX!>><!>
// KT-11354 AE from DescriptorResolver // KT-11354 AE from DescriptorResolver
open class L<E>() open class L<E>()
class M<C> : L<<!TYPE_ARGUMENTS_NOT_ALLOWED!>C<C><!>>() class M<C> : L<C<!TYPE_ARGUMENTS_NOT_ALLOWED!><C><!>>()