FIR: fix private-to-this corner case with outer class type parameter
Related to KT-49875
This commit is contained in:
+5
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||||
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
|||||||
import org.jetbrains.kotlin.fir.extensions.*
|
import org.jetbrains.kotlin.fir.extensions.*
|
||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||||
@@ -321,7 +323,9 @@ class FirStatusResolver(
|
|||||||
return !type.lookupTag.typeParameterSymbol.fir.variance.allowsPosition(requiredVariance)
|
return !type.lookupTag.typeParameterSymbol.fir.variance.allowsPosition(requiredVariance)
|
||||||
}
|
}
|
||||||
if (type is ConeClassLikeType) {
|
if (type is ConeClassLikeType) {
|
||||||
for (argument in type.typeArguments) {
|
val classLike = type.lookupTag.toSymbol(session)?.fir
|
||||||
|
for ((index, argument) in type.typeArguments.withIndex()) {
|
||||||
|
if (classLike?.typeParameters?.getOrNull(index) is FirOuterClassTypeParameterRef) continue
|
||||||
val (argType, requiredVarianceForArgument) = when (argument) {
|
val (argType, requiredVarianceForArgument) = when (argument) {
|
||||||
is ConeKotlinTypeProjectionOut -> argument.type to requiredVariance
|
is ConeKotlinTypeProjectionOut -> argument.type to requiredVariance
|
||||||
is ConeKotlinTypeProjectionIn -> argument.type to requiredVariance.opposite()
|
is ConeKotlinTypeProjectionIn -> argument.type to requiredVariance.opposite()
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
class A<in T>(t: T) {
|
class A<in T>(t: T) {
|
||||||
private val t: T = t // PRIVATE_TO_THIS
|
private val t: T = t // PRIVATE_TO_THIS
|
||||||
|
|
||||||
|
private val i: B = B()
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val x: T = t // Ok
|
val x: T = t // Ok
|
||||||
val y: T = this.t // Ok
|
val y: T = this.t // Ok
|
||||||
@@ -11,4 +13,14 @@ class A<in T>(t: T) {
|
|||||||
fun foo(a: A<String>) {
|
fun foo(a: A<String>) {
|
||||||
val x: String = a.<!INVISIBLE_REFERENCE!>t<!> // Invisible!
|
val x: String = a.<!INVISIBLE_REFERENCE!>t<!> // Invisible!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fun bar(a: A<*>) {
|
||||||
|
a.<!INVISIBLE_REFERENCE!>t<!> // Invisible!
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class B {
|
||||||
|
fun baz(a: A<*>) {
|
||||||
|
a.i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ FILE: privateToThis.fir.kt
|
|||||||
private/*private to this*/ final val t: R|T| = R|<local>/t|
|
private/*private to this*/ final val t: R|T| = R|<local>/t|
|
||||||
private/*private to this*/ get(): R|T|
|
private/*private to this*/ get(): R|T|
|
||||||
|
|
||||||
|
private final val i: R|A.B<T>| = this@R|/A|.R|SubstitutionOverride</A.B.B>|()
|
||||||
|
private get(): R|A.B<T>|
|
||||||
|
|
||||||
public final fun test(): R|kotlin/Unit| {
|
public final fun test(): R|kotlin/Unit| {
|
||||||
lval x: R|T| = this@R|/A|.R|/A.t|
|
lval x: R|T| = this@R|/A|.R|/A.t|
|
||||||
lval y: R|T| = this@R|/A|.R|/A.t|
|
lval y: R|T| = this@R|/A|.R|/A.t|
|
||||||
@@ -16,4 +19,19 @@ FILE: privateToThis.fir.kt
|
|||||||
lval x: R|kotlin/String| = R|<local>/a|.<HIDDEN: /A.t is invisible>#
|
lval x: R|kotlin/String| = R|<local>/a|.<HIDDEN: /A.t is invisible>#
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final fun bar(a: R|A<*>|): R|kotlin/Unit| {
|
||||||
|
R|<local>/a|.<HIDDEN: /A.t is invisible>#
|
||||||
|
}
|
||||||
|
|
||||||
|
public final inner class B<in T> : R|kotlin/Any| {
|
||||||
|
public A<T>.constructor(): R|A.B<T>| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final fun baz(a: R|A<*>|): R|kotlin/Unit| {
|
||||||
|
R|<local>/a|.R|SubstitutionOverride</A.i: R|A.B<CapturedType(*)>|>|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
class A<in T>(t: T) {
|
class A<in T>(t: T) {
|
||||||
private val t: T = t // PRIVATE_TO_THIS
|
private val t: T = t // PRIVATE_TO_THIS
|
||||||
|
|
||||||
|
private val i: B = B()
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val x: T = t // Ok
|
val x: T = t // Ok
|
||||||
val y: T = this.t // Ok
|
val y: T = this.t // Ok
|
||||||
@@ -11,4 +13,14 @@ class A<in T>(t: T) {
|
|||||||
fun foo(a: A<String>) {
|
fun foo(a: A<String>) {
|
||||||
val x: String = a.<!INVISIBLE_MEMBER!>t<!> // Invisible!
|
val x: String = a.<!INVISIBLE_MEMBER!>t<!> // Invisible!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun bar(a: A<*>) {
|
||||||
|
a.<!INVISIBLE_MEMBER!>t<!> // Invisible!
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class B {
|
||||||
|
fun baz(a: A<*>) {
|
||||||
|
a.i
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,20 @@ package
|
|||||||
|
|
||||||
public final class A</*0*/ in T> {
|
public final class A</*0*/ in T> {
|
||||||
public constructor A</*0*/ in T>(/*0*/ t: T)
|
public constructor A</*0*/ in T>(/*0*/ t: T)
|
||||||
|
private final val i: A<T>.B
|
||||||
private/*private to this*/ final val t: T
|
private/*private to this*/ final val t: T
|
||||||
|
public final fun bar(/*0*/ a: A<*>): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public final fun foo(/*0*/ a: A<kotlin.String>): kotlin.Unit
|
public final fun foo(/*0*/ a: A<kotlin.String>): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public final fun test(): kotlin.Unit
|
public final fun test(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
public final inner class B /*captured type parameters: /*0*/ in T*/ {
|
||||||
|
public constructor B()
|
||||||
|
public final fun baz(/*0*/ a: A<*>): kotlin.Unit
|
||||||
|
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