Skip to content

Commit 8e0919e

Browse files
committed
[K2/JS] Use declaration session for looking up containing declaration
There was a couple of helper functions, in particular hasAnnotationOrInsideAnnotatedClass, with looked up containing class or file of declaration, using call-site session. This is incorrect because it can find a file of actual declaration, instead of expect one, with unpredictable result. ^KT-67978 Fixed
1 parent 644dd05 commit 8e0919e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/FirJsHelpers.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ fun FirBasedSymbol<*>.isExportedObject(session: FirSession): Boolean {
122122
return when {
123123
hasAnnotationOrInsideAnnotatedClass(JsStandardClassIds.Annotations.JsExportIgnore, session) -> false
124124
hasAnnotationOrInsideAnnotatedClass(JsStandardClassIds.Annotations.JsExport, session) -> true
125-
else -> getContainingFile(session)?.hasAnnotation(JsStandardClassIds.Annotations.JsExport, session) == true
125+
else -> getContainingFile()?.hasAnnotation(JsStandardClassIds.Annotations.JsExport, session) == true
126126
}
127127
}
128128

129-
internal fun FirBasedSymbol<*>.getContainingFile(session: FirSession): FirFile? {
129+
internal fun FirBasedSymbol<*>.getContainingFile(): FirFile? {
130130
return when (this) {
131-
is FirCallableSymbol<*> -> session.firProvider.getFirCallableContainerFile(this)
132-
is FirClassLikeSymbol<*> -> session.firProvider.getFirClassifierContainerFileIfAny(this)
131+
is FirCallableSymbol<*> -> moduleData.session.firProvider.getFirCallableContainerFile(this)
132+
is FirClassLikeSymbol<*> -> moduleData.session.firProvider.getFirClassifierContainerFileIfAny(this)
133133
else -> return null
134134
}
135135
}

compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/FirJsModuleCheckUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal fun checkJsModuleUsage(
3737

3838
val calleeSession = callee.moduleData.session
3939
val calleeRoot = getRootClassLikeSymbolOrSelf(callee, calleeSession)
40-
val calleeContainingFile = calleeRoot.getContainingFile(calleeSession)
40+
val calleeContainingFile = calleeRoot.getContainingFile()
4141

4242
val callToModule = calleeRoot.getAnnotationStringParameter(JsStandardClassIds.Annotations.JsModule, calleeSession) != null ||
4343
calleeContainingFile?.symbol?.getAnnotationStringParameter(JsStandardClassIds.Annotations.JsModule, calleeSession) != null

compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ val CheckerContext.isTopLevel get() = containingDeclarations.lastOrNull().let {
791791

792792
fun FirBasedSymbol<*>.hasAnnotationOrInsideAnnotatedClass(classId: ClassId, session: FirSession): Boolean {
793793
if (hasAnnotation(classId, session)) return true
794-
val container = getContainingClassSymbol(session) ?: return false
794+
val container = getContainingClassSymbol(moduleData.session) ?: return false
795795
return container.hasAnnotationOrInsideAnnotatedClass(classId, session)
796796
}
797797

compiler/testData/diagnostics/tests/multiplatform/expectsWithJsExport.fir.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ expect class <!WRONG_EXPORTED_DECLARATION!>WithExportOnExpect<!> {
1313
}
1414

1515
expect class WithExportOnActual {
16-
<!WRONG_EXPORTED_DECLARATION!>fun foo()<!>
17-
<!WRONG_EXPORTED_DECLARATION, WRONG_EXPORTED_DECLARATION!>val bar: Int<!>
16+
fun foo()
17+
val bar: Int
1818
}
1919

2020
expect class WithExportTypealiasOnActual {
21-
<!WRONG_EXPORTED_DECLARATION!>fun foo()<!>
22-
<!WRONG_EXPORTED_DECLARATION, WRONG_EXPORTED_DECLARATION!>val bar: Int<!>
21+
fun foo()
22+
val bar: Int
2323
}
2424

25-
expect class <!WRONG_EXPORTED_DECLARATION!>WithFileExportOnActual<!> {
25+
expect class WithFileExportOnActual {
2626
fun foo()
2727
val bar: Int
2828
}
2929

3030
// FILE: common2.kt
3131
@file:Export
3232

33-
expect class WithExportOnExpectFile {
34-
fun foo()
35-
val bar: Int
33+
expect class <!WRONG_EXPORTED_DECLARATION!>WithExportOnExpectFile<!> {
34+
<!WRONG_EXPORTED_DECLARATION!>fun foo()<!>
35+
<!WRONG_EXPORTED_DECLARATION, WRONG_EXPORTED_DECLARATION!>val bar: Int<!>
3636
}
3737

3838
// MODULE: m1-js()()(m1-common)

0 commit comments

Comments
 (0)