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