[JS FIR] Rework JS_NAME_CLASH diagnostic for constructors
- Fix a false positive JS_NAME_CLASH report on constructors from different classes but with the same JsName. - Allow the same JsName for class constructors and other top-level declarations. This behavior differs from K1, but it is correct since there is no real name clash in the generated JS code. ^KT-64867 Fixed
This commit is contained in:
committed by
Space Team
parent
2708c74d9c
commit
5da4d31d37
+2
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.js.checkers.FirJsStableName
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.constructors
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
@@ -118,6 +119,7 @@ object FirJsNameClashClassMembersChecker : FirClassChecker() {
|
|||||||
|
|
||||||
val scope = declaration.symbol.unsubstitutedScope(context)
|
val scope = declaration.symbol.unsubstitutedScope(context)
|
||||||
|
|
||||||
|
scope.processDeclaredConstructors(allSymbols::add)
|
||||||
addAllSymbolsFrom(scope.collectAllFunctions())
|
addAllSymbolsFrom(scope.collectAllFunctions())
|
||||||
addAllSymbolsFrom(scope.collectAllProperties())
|
addAllSymbolsFrom(scope.collectAllProperties())
|
||||||
|
|
||||||
|
|||||||
-5
@@ -35,11 +35,6 @@ object FirJsNameClashFileTopLevelDeclarationsChecker : FirFileChecker() {
|
|||||||
val topLevelDeclarationsWithStableName = mutableMapOf<String, MutableList<FirJsStableName>>()
|
val topLevelDeclarationsWithStableName = mutableMapOf<String, MutableList<FirJsStableName>>()
|
||||||
for (topLevelDeclaration in declaration.declarations) {
|
for (topLevelDeclaration in declaration.declarations) {
|
||||||
topLevelDeclarationsWithStableName.addStableName(topLevelDeclaration.symbol, context)
|
topLevelDeclarationsWithStableName.addStableName(topLevelDeclaration.symbol, context)
|
||||||
if (topLevelDeclaration is FirClass) {
|
|
||||||
for (classConstructor in topLevelDeclaration.constructors(context.session)) {
|
|
||||||
topLevelDeclarationsWithStableName.addStableName(classConstructor, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for ((name, stableNames) in topLevelDeclarationsWithStableName.entries) {
|
for ((name, stableNames) in topLevelDeclarationsWithStableName.entries) {
|
||||||
for (symbol in stableNames) {
|
for (symbol in stableNames) {
|
||||||
|
|||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// FIR_DIFFERENCE
|
||||||
|
// K1 performs a check for legacy JS BE; however, this is not relevant for IR BE because in the generated JS code,
|
||||||
|
// there is no name clash between the constructor with JsName and the other top-level declarations with the same JsName.
|
||||||
|
// Keep K1 as it is, but for K2, implement a more relevant check without the clash.
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class A(val x: String) {
|
||||||
|
@JsName("aa") constructor(x: Int) : this("int $x")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun aa() {}
|
||||||
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_DIFFERENCE
|
||||||
|
// K1 performs a check for legacy JS BE; however, this is not relevant for IR BE because in the generated JS code,
|
||||||
|
// there is no name clash between the constructor with JsName and the other top-level declarations with the same JsName.
|
||||||
|
// Keep K1 as it is, but for K2, implement a more relevant check without the clash.
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
class A(val x: String) {
|
class A(val x: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user