K2: don't use outer class type parameters during nested class TP resolve
Before this commit, we allowed access to outer class type parameters during resolve of type parameter bounds of a nested class. In fact, outer type parameters are accessible in this situation only if it's an inner class (or a local class). This commit forbids such a usage. In the earlier fix of KT-57209 the same was done for regular type reference resolve. #KT-61459 Fixed #KT-61959 Fixed
This commit is contained in:
committed by
Space Team
parent
cdc197c723
commit
9cf1d36e5e
-1
@@ -1,6 +1,5 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
class Outer<MyParam> {
|
class Outer<MyParam> {
|
||||||
// TODO this test has an error, MyParam should not be resolved here. See KT-61959
|
|
||||||
class Nested<T : <expr>MyParam</expr>>
|
class Nested<T : <expr>MyParam</expr>>
|
||||||
}
|
}
|
||||||
+4
-4
@@ -20,7 +20,7 @@ Tower Data Context:
|
|||||||
Element 8
|
Element 8
|
||||||
Scope: FirNestedClassifierScopeImpl
|
Scope: FirNestedClassifierScopeImpl
|
||||||
Classifiers:
|
Classifiers:
|
||||||
FirRegularClassSymbol public final class Nested<T : R|MyParam|> : R|kotlin/Any|
|
FirRegularClassSymbol public final class Nested<T : <ERROR TYPE REF: Symbol not found for MyParam>> : R|kotlin/Any|
|
||||||
Element 9
|
Element 9
|
||||||
Implicit receiver:
|
Implicit receiver:
|
||||||
FirRegularClassSymbol public final class Outer<MyParam> : R|kotlin/Any|
|
FirRegularClassSymbol public final class Outer<MyParam> : R|kotlin/Any|
|
||||||
@@ -28,7 +28,7 @@ Tower Data Context:
|
|||||||
Element 10
|
Element 10
|
||||||
Scope: FirMemberTypeParameterScope
|
Scope: FirMemberTypeParameterScope
|
||||||
Classifiers:
|
Classifiers:
|
||||||
FirTypeParameterSymbol T : R|MyParam|
|
FirTypeParameterSymbol T : <ERROR TYPE REF: Symbol not found for MyParam>
|
||||||
|
|
||||||
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeBound.kt
|
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeBound.kt
|
||||||
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
|
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
|
||||||
@@ -36,8 +36,8 @@ FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeBound.kt
|
|||||||
super<R|kotlin/Any|>()
|
super<R|kotlin/Any|>()
|
||||||
}
|
}
|
||||||
|
|
||||||
public final [ResolvedTo(STATUS)] class Nested<[ResolvedTo(STATUS)] T : R|MyParam|> : R|kotlin/Any| {
|
public final [ResolvedTo(STATUS)] class Nested<[ResolvedTo(STATUS)] T : <ERROR TYPE REF: Symbol not found for MyParam>> : R|kotlin/Any| {
|
||||||
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] T : R|MyParam|>(): R|test/Outer.Nested<T>| {
|
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] T : <ERROR TYPE REF: Symbol not found for MyParam>>(): R|test/Outer.Nested<T>| {
|
||||||
super<R|kotlin/Any|>()
|
super<R|kotlin/Any|>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
@@ -125,6 +125,10 @@ open class FirTypeResolveTransformer(
|
|||||||
|
|
||||||
fun transformClassTypeParameters(regularClass: FirRegularClass, data: Any?) {
|
fun transformClassTypeParameters(regularClass: FirRegularClass, data: Any?) {
|
||||||
withScopeCleanup {
|
withScopeCleanup {
|
||||||
|
// Remove type parameter scopes for classes that are neither inner nor local
|
||||||
|
if (removeOuterTypeParameterScope(regularClass)) {
|
||||||
|
this.scopes = staticScopes
|
||||||
|
}
|
||||||
addTypeParametersScope(regularClass)
|
addTypeParametersScope(regularClass)
|
||||||
regularClass.typeParameters.forEach {
|
regularClass.typeParameters.forEach {
|
||||||
it.accept(this, data)
|
it.accept(this, data)
|
||||||
|
|||||||
Vendored
-22
@@ -1,22 +0,0 @@
|
|||||||
// ISSUE: KT-61459
|
|
||||||
|
|
||||||
interface Alarm {
|
|
||||||
interface Builder<Self : Builder<Self>> {
|
|
||||||
fun build(): Alarm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractAlarm<Self : AbstractAlarm<Self, Builder>, Builder : AbstractAlarm.Builder<Builder, Self>>(
|
|
||||||
val identifier: String,
|
|
||||||
) : Alarm {
|
|
||||||
abstract class Builder<Self : Builder<!TYPE_ARGUMENTS_NOT_ALLOWED!><Self, Built><!>, Built : AbstractAlarm<Built, <!UPPER_BOUND_VIOLATED!>Self<!>>> : Alarm.Builder<<!UPPER_BOUND_VIOLATED!>Self<!>> {
|
|
||||||
private var identifier: String = ""
|
|
||||||
|
|
||||||
fun setIdentifier(text: String): Self {
|
|
||||||
this.identifier = text
|
|
||||||
return this <!UNCHECKED_CAST!>as Self<!>
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun build(): Built = TODO()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// ISSUE: KT-61459
|
// ISSUE: KT-61459
|
||||||
|
|
||||||
interface Alarm {
|
interface Alarm {
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
// ISSUE: KT-61959
|
|
||||||
|
|
||||||
package test
|
|
||||||
|
|
||||||
interface OuterParam
|
|
||||||
|
|
||||||
class Outer<OuterParam> {
|
|
||||||
class Nested<NestedParam : OuterParam>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
Outer.Nested<<!UPPER_BOUND_VIOLATED!>OuterParam<!>>()
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// ISSUE: KT-61959
|
// ISSUE: KT-61959
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|||||||
Reference in New Issue
Block a user