[FIR] Use class scope to get constructors for redeclaration check

#KT-60793 Fixed
This commit is contained in:
Kirill Rakhman
2023-07-28 15:31:45 +02:00
committed by Space Team
parent e7c589a573
commit 0a469ff3b9
5 changed files with 39 additions and 9 deletions
@@ -129,8 +129,10 @@ private fun groupTopLevelByName(declarations: List<FirDeclaration>): Map<Name, D
* Collects FirDeclarations for further analysis.
*/
class FirDeclarationInspector(
private val session: FirSession,
private val context: CheckerContext,
) {
private val session: FirSession get() = context.sessionHolder.session
val declarationConflictingSymbols: HashMap<FirDeclaration, SmartSet<FirBasedSymbol<*>>> = hashMapOf()
fun collectClassMembers(klass: FirRegularClass) {
@@ -184,6 +186,7 @@ class FirDeclarationInspector(
* | constructors of classes | X | | | | |
* | properties | | | X | X | X |
*/
@OptIn(SymbolInternals::class)
@Suppress("GrazieInspection")
fun collectTopLevel(file: FirFile, packageMemberScope: FirPackageMemberScope) {
@@ -224,11 +227,10 @@ class FirDeclarationInspector(
if (conflictingSymbol.classKind == ClassKind.OBJECT || conflictingSymbol.classKind == ClassKind.ENUM_ENTRY) return
conflictingSymbol.lazyResolveToPhase(FirResolvePhase.STATUS)
@OptIn(SymbolInternals::class)
val classWithSameName = conflictingSymbol.fir
classWithSameName.declarations.filterIsInstance<FirConstructor>().forEach { constructor ->
val ctorRepresentation = FirRedeclarationPresenter.represent(constructor, classWithSameName)
collect(group.simpleFunctions, conflictingSymbol = constructor.symbol, conflictingPresentation = ctorRepresentation)
classWithSameName.unsubstitutedScope(context).processDeclaredConstructors { constructor ->
val ctorRepresentation = FirRedeclarationPresenter.represent(constructor.fir, classWithSameName)
collect(group.simpleFunctions, conflictingSymbol = constructor, conflictingPresentation = ctorRepresentation)
}
}
}
@@ -27,7 +27,7 @@ object FirConflictsDeclarationChecker : FirBasicDeclarationChecker() {
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
when (declaration) {
is FirFile -> {
val inspector = FirDeclarationInspector(context.sessionHolder.session)
val inspector = FirDeclarationInspector(context)
checkFile(declaration, inspector, context)
reportConflicts(reporter, context, inspector.declarationConflictingSymbols)
}
@@ -35,7 +35,7 @@ object FirConflictsDeclarationChecker : FirBasicDeclarationChecker() {
if (declaration.source?.kind !is KtFakeSourceElementKind) {
checkForLocalRedeclarations(declaration.typeParameters, context, reporter)
}
val inspector = FirDeclarationInspector(context.sessionHolder.session)
val inspector = FirDeclarationInspector(context)
inspector.collectClassMembers(declaration)
reportConflicts(reporter, context, inspector.declarationConflictingSymbols)
}
@@ -1,5 +1,13 @@
// constructor vs. fun overload
// FILE: J.java
package constructorVsFun;
public class J {
public J(String s) {}
}
// FILE: test.kt
package constructorVsFun
class a<!CONFLICTING_OVERLOADS!>()<!> { }
@@ -26,4 +34,6 @@ class Rtyu {
companion object {
class ololo() { }
}
}
}
<!CONFLICTING_OVERLOADS!>fun J(s: String)<!> { }
@@ -1,5 +1,13 @@
// constructor vs. fun overload
// FILE: J.java
package constructorVsFun;
public class J {
public J(String s) {}
}
// FILE: test.kt
package constructorVsFun
class a<!CONFLICTING_OVERLOADS!>()<!> { }
@@ -26,4 +34,6 @@ class Rtyu {
companion object {
class ololo() { }
}
}
}
fun J(s: String) { }
@@ -1,8 +1,16 @@
package
package constructorVsFun {
public fun J(/*0*/ s: kotlin.String): kotlin.Unit
public fun a(): kotlin.Int
public open class J {
public constructor J(/*0*/ s: kotlin.String!)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Rtyu {
public constructor Rtyu()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean