diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt index 5caccd0ee99..0c0ed1bd07a 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt @@ -122,7 +122,10 @@ class JavaSymbolProvider( classId, { val foundClass = findClass(classId, content) - if (foundClass == null || foundClass.annotations.any { it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME }) { + if (foundClass == null || foundClass.annotations.any { + it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME + } + ) { null to null } else { FirRegularClassSymbol(classId) to foundClass @@ -136,13 +139,13 @@ class JavaSymbolProvider( if (!isTopLevel) { val parentId = ClassId(classId.packageFqName, parentFqName, false) val parentClassSymbol = getClassLikeSymbolByFqName(parentId) - val parentStack = parentClassTypeParameterStackCache[parentClassSymbol] ?: - (parentClassSymbol?.fir as? FirJavaClass)?.javaTypeParameterStack + val parentStack = parentClassTypeParameterStackCache[parentClassSymbol] + ?: (parentClassSymbol?.fir as? FirJavaClass)?.javaTypeParameterStack if (parentStack != null) { javaTypeParameterStack.addStack(parentStack) } } - buildJavaClass { + val firJavaClass = buildJavaClass { source = (javaClass as? JavaElementImpl<*>)?.psi?.toFirSourceElement() session = this@JavaSymbolProvider.session symbol = firSymbol @@ -158,11 +161,6 @@ class JavaSymbolProvider( scopeProvider = this@JavaSymbolProvider.scopeProvider typeParameters += foundClass.typeParameters.convertTypeParameters(javaTypeParameterStack) addAnnotationsFrom(this@JavaSymbolProvider.session, javaClass, javaTypeParameterStack) - for (supertype in javaClass.supertypes) { - superTypeRefs += supertype.toFirResolvedTypeRef( - this@JavaSymbolProvider.session, javaTypeParameterStack, typeParametersNullability = ConeNullability.UNKNOWN - ) - } // TODO: may be we can process fields & methods later. // However, they should be built up to override resolve stage for (javaField in javaClass.fields) { @@ -218,7 +216,7 @@ class JavaSymbolProvider( ): FirJavaConstructorBuilder { val constructorSymbol = FirConstructorSymbol(constructorId) val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack) - val firJavaConstructor = FirJavaConstructorBuilder().apply { + return FirJavaConstructorBuilder().apply { source = psi?.toFirSourceElement() session = this@JavaSymbolProvider.session symbol = constructorSymbol @@ -233,7 +231,6 @@ class JavaSymbolProvider( } typeParameters += classTypeParameters } - return firJavaConstructor } if (javaClassDeclaredConstructors.isEmpty() && javaClass.classKind == ClassKind.CLASS) { @@ -260,6 +257,13 @@ class JavaSymbolProvider( isNotSam = isNotSam() parentClassTypeParameterStackCache.remove(firSymbol) } + firJavaClass.replaceSuperTypeRefs( + javaClass.supertypes.map { supertype -> + supertype.toFirResolvedTypeRef( + this@JavaSymbolProvider.session, javaTypeParameterStack, typeParametersNullability = ConeNullability.UNKNOWN + ) + } + ) } } } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.kt b/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.kt index aec8e8d28ce..cb863d7ced1 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.kt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.kt @@ -1,35 +1,33 @@ -// Compiler crashes on this tests so it's commented +// FILE: K1.kt +class K2: J1() { + class Q : Nested() + fun bar() { + foo() + baz() -//// FILE: K1.kt -//class K2: J1() { -// class Q : Nested() -// fun bar() { -// foo() -// baz() -// -// superClass() -// superI() -// } -//} -// -//// FILE: J1.java -//public class J1 extends K2() { -// public class Nested {} -// -// void baz() {} -//} -// -//// FILE: K2.kt -//open class KFirst : SuperClass(), SuperI { -// fun foo() { -// } -//} -// -//// FILE: K3.kt -//abstract class SuperClass { -// fun superClass() {} -//} -// -//interface SuperI { -// fun superI() {} -//} + superClass() + superI() + } +} + +// FILE: J1.java +public class J1 extends K2() { + public class Nested {} + + void baz() {} +} + +// FILE: K2.kt +open class KFirst : SuperClass(), SuperI { + fun foo() { + } +} + +// FILE: K3.kt +abstract class SuperClass { + fun superClass() {} +} + +interface SuperI { + fun superI() {} +} diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.txt b/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.txt index 65bcd527342..4c55ec3e552 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems/KJKComplexHierarchyNestedLoop.txt @@ -1,3 +1,46 @@ FILE: K1.kt + public final class K2 : R|J1| { + public constructor(): R|K2| { + super() + } + + public final class Q : R|ERROR CLASS: Symbol not found, for `Nested`| { + public constructor(): R|K2.Q| { + super() + } + + } + + public final fun bar(): R|kotlin/Unit| { + #() + #() + #() + #() + } + + } FILE: K2.kt + public open class KFirst : R|SuperClass|, R|SuperI| { + public constructor(): R|KFirst| { + super() + } + + public final fun foo(): R|kotlin/Unit| { + } + + } FILE: K3.kt + public abstract class SuperClass : R|kotlin/Any| { + public constructor(): R|SuperClass| { + super() + } + + public final fun superClass(): R|kotlin/Unit| { + } + + } + public abstract interface SuperI : R|kotlin/Any| { + public open fun superI(): R|kotlin/Unit| { + } + + } diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.fail b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.fail deleted file mode 100644 index 8b36892887f..00000000000 --- a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.fail +++ /dev/null @@ -1,2 +0,0 @@ -Failures detected in FirSupertypeResolverTransformer, file: /K.kt -Cause: kotlin.UninitializedPropertyAccessException: lateinit property fir has not been initialized