Files
kotlin-fork/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.fir.kt
T
Brian Norman e10a9263d0 [FIR] Only inherit class type parameters if inner class
Nested classes which are not inner class should not be able to access
type parameters of the outer class. Make sure access is not available
when resolving super types.

#KT-54748 Fixed
2023-05-31 16:25:51 +00:00

55 lines
1.4 KiB
Kotlin
Vendored

// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY
class A<R1, R2, R3, R4>
private fun <E> foobar() = {
open class LocalOuter<X, Y> {
inner class LocalInner<Z> {
fun a() = A<E, X, Y, Z>()
}
typealias LocalAlias<W> = A<E, X, Y, W>
}
class Derived : LocalOuter<Double, Short>() {
fun foo(): LocalInner<Long> = null!!
fun bar(): <!UNRESOLVED_REFERENCE!>LocalAlias<Char><!> = null!!
}
Derived()
}
private fun noParameters() = {
open class LocalOuter2<X, Y> {
inner class LocalInner2<Z> {
fun a() = A<Any, X, Y, Z>()
}
typealias LocalAlias2<W> = A<Any, X, Y, W>
}
class Derived2 : LocalOuter2<Double, Short>() {
fun foo(): LocalInner2<Long> = null!!
fun bar(): <!UNRESOLVED_REFERENCE!>LocalAlias2<Char><!> = null!!
}
Derived2()
}
fun test() {
var x = foobar<String>()
x = foobar<String>()
x().foo().a() checkType { _<A<String, Double, Short, Long>>() }
x().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<String, Double, Short, Char>>() }
x = <!ASSIGNMENT_TYPE_MISMATCH!>foobar<Int>()<!>
var y = noParameters()
y = noParameters()
y().foo().a() checkType { _<A<Any, Double, Short, Long>>() }
y().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<Any, Double, Short, Char>>() }
}