Skip to content

Commit f1b5dd2

Browse files
authored
Merge pull request #243 from nikolaykasyanov/hidden-from-objc-container-type
Imply @NativeCoroutinesIgnore when container is @HiddenFromObjC
2 parents a84bdbf + f9c6ee5 commit f1b5dd2

File tree

6 files changed

+140
-2
lines changed

6 files changed

+140
-2
lines changed

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/classic/utils/ObjCRefinement.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
88
internal val DeclarationDescriptor.isRefined: Boolean
99
get() = annotations.any { annotation ->
1010
!annotation.isNativeCoroutinesAnnotation && annotation.isRefinementAnnotation
11-
}
11+
} || (containingDeclaration?.isHiddenFromObjC ?: false)
12+
13+
private val DeclarationDescriptor.isHiddenFromObjC: Boolean
14+
get() = annotations.any { annotation ->
15+
annotation.isHiddenFromObjCAnnotation
16+
} || (containingDeclaration?.isHiddenFromObjC ?: false)
1217

1318
@Suppress("UnstableApiUsage")
1419
private val AnnotationDescriptor.isRefinementAnnotation: Boolean
1520
get() = annotationClass?.annotations?.any { metaAnnotation ->
1621
val fqName = metaAnnotation.fqName
1722
fqName == FqNames.hidesFromObjC || fqName == FqNames.refinesInSwift
1823
} ?: false
24+
25+
private val AnnotationDescriptor.isHiddenFromObjCAnnotation: Boolean
26+
get() = annotationClass?.annotations?.any { metaAnnotation ->
27+
metaAnnotation.fqName == FqNames.hidesFromObjC
28+
} ?: false

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/fir/utils/ObjCRefinement.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@ package com.rickclephas.kmp.nativecoroutines.compiler.fir.utils
33
import com.rickclephas.kmp.nativecoroutines.compiler.utils.ClassIds
44
import org.jetbrains.kotlin.fir.FirSession
55
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
6+
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
67
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassId
78
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassLikeSymbol
89
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
10+
import org.jetbrains.kotlin.fir.resolve.getContainingClass
11+
import org.jetbrains.kotlin.fir.resolve.getContainingDeclaration
912

1013
internal fun FirCallableDeclaration.isRefined(session: FirSession): Boolean =
1114
annotations.any { annotation ->
1215
!annotation.isNativeCoroutinesAnnotation(session) && annotation.isRefinementAnnotation(session)
13-
}
16+
} || (getContainingClass()?.isHiddenFromObjC(session) ?: false)
17+
18+
private fun FirClassLikeDeclaration.isHiddenFromObjC(session: FirSession): Boolean =
19+
annotations.any { annotation ->
20+
annotation.isHidingFromObjCAnnotation(session)
21+
} || (getContainingDeclaration(session)?.isHiddenFromObjC(session) ?: false)
1422

1523
private fun FirAnnotation.isRefinementAnnotation(session: FirSession): Boolean =
1624
toAnnotationClassLikeSymbol(session)?.resolvedAnnotationsWithClassIds.orEmpty().any { metaAnnotation ->
1725
val classId = metaAnnotation.toAnnotationClassId(session)
1826
classId == ClassIds.hidesFromObjC || classId == ClassIds.refinesInSwift
1927
}
28+
29+
private fun FirAnnotation.isHidingFromObjCAnnotation(session: FirSession): Boolean =
30+
toAnnotationClassLikeSymbol(session)?.resolvedAnnotationsWithClassIds.orEmpty().any { metaAnnotation ->
31+
val classId = metaAnnotation.toAnnotationClassId(session)
32+
classId == ClassIds.hidesFromObjC
33+
}

kmp-nativecoroutines-compiler/src/testData/diagnostics/exposedAnnotated.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ interface TestInterface {
7777
val flowInterfaceProperty: Flow<Int>
7878
}
7979

80+
@OptIn(ExperimentalObjCRefinement::class)
81+
@HiddenFromObjC
82+
interface TestHiddenFromObjCInterface {
83+
suspend fun suspendInterfaceFunction(): Int
84+
85+
val flowInterfaceProperty: Flow<Int>
86+
87+
class Nested {
88+
suspend fun suspendInterfaceFunction(): Int = 0
89+
90+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
91+
}
92+
}
93+
8094
class TestClassA: TestInterface {
8195

8296
override suspend fun suspendInterfaceFunction(): Int = 0
@@ -120,3 +134,19 @@ actual class TestClassC {
120134

121135
actual val flowProperty: Flow<Int> get() = throw Throwable()
122136
}
137+
138+
class TestClassD {
139+
@NativeCoroutines
140+
suspend fun suspendInterfaceFunction(): Int = 0
141+
142+
@NativeCoroutines
143+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
144+
145+
@OptIn(ExperimentalObjCRefinement::class)
146+
@HiddenFromObjC
147+
interface Nested {
148+
suspend fun suspendInterfaceFunction(): Int
149+
150+
val flowInterfaceProperty: Flow<Int>
151+
}
152+
}

kmp-nativecoroutines-compiler/src/testData/diagnostics/exposedError.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ interface TestInterface {
5959
val flowInterfaceProperty: <!EXPOSED_FLOW_TYPE_ERROR!>Flow<Int><!>
6060
}
6161

62+
@OptIn(ExperimentalObjCRefinement::class)
63+
@HiddenFromObjC
64+
interface TestHiddenFromObjCInterface {
65+
suspend fun suspendInterfaceFunction(): Int
66+
67+
val flowInterfaceProperty: Flow<Int>
68+
69+
class Nested {
70+
suspend fun suspendInterfaceFunction(): Int = 0
71+
72+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
73+
}
74+
}
75+
6276
class TestClassA: TestInterface {
6377

6478
override suspend fun suspendInterfaceFunction(): Int = 0
@@ -96,3 +110,17 @@ actual class TestClassC {
96110

97111
actual val flowProperty: Flow<Int> get() = throw Throwable()
98112
}
113+
114+
class TestClassD {
115+
<!EXPOSED_SUSPEND_FUNCTION_ERROR!>suspend<!> fun suspendInterfaceFunction(): Int = 0
116+
117+
val flowInterfaceProperty: <!EXPOSED_FLOW_TYPE_ERROR!>Flow<Int><!> = throw Throwable()
118+
119+
@OptIn(ExperimentalObjCRefinement::class)
120+
@HiddenFromObjC
121+
interface Nested {
122+
suspend fun suspendInterfaceFunction(): Int
123+
124+
val flowInterfaceProperty: Flow<Int>
125+
}
126+
}

kmp-nativecoroutines-compiler/src/testData/diagnostics/exposedNone.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ interface TestInterface {
5959
val flowInterfaceProperty: Flow<Int>
6060
}
6161

62+
@OptIn(ExperimentalObjCRefinement::class)
63+
@HiddenFromObjC
64+
interface TestHiddenFromObjCInterface {
65+
suspend fun suspendInterfaceFunction(): Int
66+
67+
val flowInterfaceProperty: Flow<Int>
68+
69+
class Nested {
70+
suspend fun suspendInterfaceFunction(): Int = 0
71+
72+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
73+
}
74+
}
75+
6276
class TestClassA: TestInterface {
6377

6478
override suspend fun suspendInterfaceFunction(): Int = 0
@@ -96,3 +110,17 @@ actual class TestClassC {
96110

97111
actual val flowProperty: Flow<Int> get() = throw Throwable()
98112
}
113+
114+
class TestClassD {
115+
suspend fun suspendInterfaceFunction(): Int = 0
116+
117+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
118+
119+
@OptIn(ExperimentalObjCRefinement::class)
120+
@HiddenFromObjC
121+
interface Nested {
122+
suspend fun suspendInterfaceFunction(): Int
123+
124+
val flowInterfaceProperty: Flow<Int>
125+
}
126+
}

kmp-nativecoroutines-compiler/src/testData/diagnostics/exposedWarning.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ interface TestInterface {
5959
val flowInterfaceProperty: <!EXPOSED_FLOW_TYPE!>Flow<Int><!>
6060
}
6161

62+
@OptIn(ExperimentalObjCRefinement::class)
63+
@HiddenFromObjC
64+
interface TestHiddenFromObjCInterface {
65+
suspend fun suspendInterfaceFunction(): Int
66+
67+
val flowInterfaceProperty: Flow<Int>
68+
69+
class Nested {
70+
suspend fun suspendInterfaceFunction(): Int = 0
71+
72+
val flowInterfaceProperty: Flow<Int> = throw Throwable()
73+
}
74+
}
75+
6276
class TestClassA: TestInterface {
6377

6478
override suspend fun suspendInterfaceFunction(): Int = 0
@@ -96,3 +110,17 @@ actual class TestClassC {
96110

97111
actual val flowProperty: Flow<Int> get() = throw Throwable()
98112
}
113+
114+
class TestClassD {
115+
<!EXPOSED_SUSPEND_FUNCTION!>suspend<!> fun suspendInterfaceFunction(): Int = 0
116+
117+
val flowInterfaceProperty: <!EXPOSED_FLOW_TYPE!>Flow<Int><!> = throw Throwable()
118+
119+
@OptIn(ExperimentalObjCRefinement::class)
120+
@HiddenFromObjC
121+
interface Nested {
122+
suspend fun suspendInterfaceFunction(): Int
123+
124+
val flowInterfaceProperty: Flow<Int>
125+
}
126+
}

0 commit comments

Comments
 (0)