sindrenm
09/18/2025, 7:49 AMfun main() {
Foo()
}
class Foo {
val bar = Bar() // fails because outerBaz is not yet initialized
val outerBaz = "Baz"
inner class Bar(
val innerBaz: String = outerBaz
)
}
Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null: method Foo$Bar.<init>, parameter innerBaz
at Foo$Bar.<init> (File.kt:-1)
at Foo$Bar.<init> (File.kt:9)
at Foo.<init> (File.kt:6)
(https://pl.kotl.in/OetJ4wyvS)
I would think/hope this was something that could be caught at compile-time. Is this is a known issue? My YouTrack-fu is failing me.sindrenm
09/18/2025, 7:51 AMfun main() {
Foo()
}
class Foo {
val bar = outerBar // compile-time error here
val outerBaz = "Baz"
}
Compilation failed:
Unresolved reference 'outerBar'.
(https://pl.kotl.in/9Io-rZ1RG)Sam
09/18/2025, 8:03 AMSam
09/18/2025, 8:05 AMSam
09/18/2025, 8:06 AMsindrenm
09/18/2025, 8:54 AM