When there are no declared constructors in Java class, make
javaConstructor's source element point to the class declaration,
making it possible to navigate from constructor's invocation there.
^KTIJ-22360 Fixed
Before, BODY_RESOLVE phase were used for them but status may be unresolved.
This caused CCE on accessing resolved status for such static enum members.
Now, those declarations are created with the status of owning enum as the status is taken from that class.
'findKotlinClassOrContent()' does not really distinguish between
outer class names and package path components, so it might return
'foo/bar/Baz.Boo' for 'foo/bar/Baz/Boo'. Possibly because
'findKotlinClassOrContent()' potentially returns a raw byte array,
ClassId checking is supposed to be performed in
'extractClassMetadata()'. For Java, it happens inside
'FirJavaFacade.findClass()', yet for Kotlin the check was absent.
Example: if C is a Kotlin class and there is an import of C.Companion.f,
a call to f will need to check if it is a constructor, for which
it will attempt to load C.Companion.f as a Java class. This involves
loading all outer classes, including C itself, as BinaryJavaClass - see
KotlinCliJavaFileManagerImpl - despite the fact that C and C.Companion
have both already been loaded from their Metadata annotations as Kotlin
classes, wasting cycles and polluting caches.
Thus the theoretical motivation for this change is to marginally speed
up FIR.
The real motivation is that with the -Xemit-jvm-type-annotations option,
kotlinc sometimes generates invalid annotations, and reading them with
BinaryJavaClass throws an exception (the Kotlin metadata however is
valid):
// MODULE: lib
// FILE: C.kt
// The constructor has an argument of type
// List<? extends Function1<? super String, Integer>>
// and a ParameterName type annotation with path
// TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)
// which is missing a WILDCARD between the two TYPE_ARGUMENTs
class C(val x: List<(name: String) -> Int>) {
companion object {
fun foo() {}
}
}
// MODULE: main(lib)
// FILE: main.kt
import C.Companion.f
fun bar() = foo() // crashes FIR
The parameter annotation should obviously be fixed too, but invalid
bytecode may already exist in the wild. Also, did I mention that this
change marginally speeds up FIR?
Using `ownerLookupTag` might be wrong in case of private constuctors
of inner classes: their owner is an Inner class, but expected
dispach receiver is Outer