[FIR] Fix isValidTypeParameterFromOuterDeclaration check for local class
This fixes an IllegalArgumentException when symbolProvider.getClassLikeSymbolByClassId is called with a local class ID. #KT-63656 Fixed
This commit is contained in:
committed by
Space Team
parent
a703f5afb8
commit
9ea4afe7c8
@@ -7,12 +7,15 @@ package org.jetbrains.kotlin.fir.resolve
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.containingClassForLocalAttr
|
import org.jetbrains.kotlin.fir.containingClassForLocalAttr
|
||||||
|
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||||
import org.jetbrains.kotlin.fir.resolve.dfa.RealVariable
|
import org.jetbrains.kotlin.fir.resolve.dfa.RealVariable
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
@@ -53,8 +56,8 @@ fun isValidTypeParameterFromOuterDeclaration(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentDeclaration is FirCallableDeclaration) {
|
if (currentDeclaration is FirCallableDeclaration) {
|
||||||
val containingClassId = currentDeclaration.symbol.callableId.classId ?: return true
|
val containingClassLookupTag = currentDeclaration.containingClassLookupTag() ?: return true
|
||||||
return containsTypeParameter(session.symbolProvider.getClassLikeSymbolByClassId(containingClassId)?.fir)
|
return containsTypeParameter(containingClassLookupTag.toSymbol(session)?.fir)
|
||||||
} else if (currentDeclaration is FirClass) {
|
} else if (currentDeclaration is FirClass) {
|
||||||
for (superTypeRef in currentDeclaration.superTypeRefs) {
|
for (superTypeRef in currentDeclaration.superTypeRefs) {
|
||||||
val superClassFir = superTypeRef.firClassLike(session) ?: return true
|
val superClassFir = superTypeRef.firClassLike(session) ?: return true
|
||||||
|
|||||||
+20
@@ -1,3 +1,4 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
import A.B.D
|
import A.B.D
|
||||||
import A.B.C
|
import A.B.C
|
||||||
import A.B.D.Innermost
|
import A.B.D.Innermost
|
||||||
@@ -19,5 +20,24 @@ class A<T> {
|
|||||||
val d: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>D?<!> = null
|
val d: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>D?<!> = null
|
||||||
|
|
||||||
val innerMost: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>Innermost<String>?<!> = null
|
val innerMost: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>Innermost<String>?<!> = null
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
object {
|
||||||
|
val something = listOf<<!OUTER_CLASS_ARGUMENTS_REQUIRED!>B<String><!>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
object {
|
||||||
|
val something = listOf<B<String>>() // False positive in K1 KT-63732
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> bar() {
|
||||||
|
data class Example(val foo: Int)
|
||||||
|
object {
|
||||||
|
val something = listOf<Example>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -1,3 +1,4 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
import A.B.D
|
import A.B.D
|
||||||
import A.B.C
|
import A.B.C
|
||||||
import A.B.D.Innermost
|
import A.B.D.Innermost
|
||||||
@@ -19,5 +20,24 @@ class A<T> {
|
|||||||
val d: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>D<!>? = null
|
val d: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>D<!>? = null
|
||||||
|
|
||||||
val innerMost: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>Innermost<!><String>? = null
|
val innerMost: <!OUTER_CLASS_ARGUMENTS_REQUIRED("class 'B'")!>Innermost<!><String>? = null
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
object {
|
||||||
|
val something = listOf<<!OUTER_CLASS_ARGUMENTS_REQUIRED!>B<!><String>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
object {
|
||||||
|
val something = listOf<<!OUTER_CLASS_ARGUMENTS_REQUIRED!>B<!><String>>() // False positive in K1 KT-63732
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> bar() {
|
||||||
|
data class Example(val foo: Int)
|
||||||
|
object {
|
||||||
|
val something = listOf<Example>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package
|
|
||||||
|
|
||||||
public final class A</*0*/ T> {
|
|
||||||
public constructor A</*0*/ T>()
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
|
|
||||||
public final inner class B</*0*/ F> /*captured type parameters: /*1*/ T*/ {
|
|
||||||
public constructor B</*0*/ F>()
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
|
|
||||||
public final inner class C</*0*/ E> /*captured type parameters: /*1*/ F, /*2*/ T*/ {
|
|
||||||
public constructor C</*0*/ E>()
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
}
|
|
||||||
|
|
||||||
public final inner class D /*captured type parameters: /*0*/ F, /*1*/ T*/ {
|
|
||||||
public constructor D()
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
|
|
||||||
public final inner class Innermost</*0*/ X> /*captured type parameters: /*1*/ F, /*2*/ T*/ {
|
|
||||||
public constructor Innermost</*0*/ X>()
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class Nested {
|
|
||||||
public constructor Nested()
|
|
||||||
public final val c: [Error type: Type for error type constructor (C)]<kotlin.Int>?
|
|
||||||
public final val d: [Error type: Type for error type constructor (D)]?
|
|
||||||
public final val innerMost: [Error type: Type for error type constructor (Innermost)]<kotlin.String>?
|
|
||||||
public final val x: [Error type: Type for error type constructor (B)]<kotlin.String>?
|
|
||||||
public final val y: [Error type: Type for error type constructor (C)]<kotlin.String, kotlin.String>?
|
|
||||||
public final val z: [Error type: Type for error type constructor (D)]<kotlin.String>?
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user