Skip to content

Commit dafe9d7

Browse files
committed
Add the required OptIn annotations
1 parent d3e24e5 commit dafe9d7

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

core/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ kotlin {
118118
kotlin.srcDir("$targetName/${suffix ?: "src"}")
119119
resources.srcDir("$targetName/${suffix?.let { it + "Resources" } ?: "resources"}")
120120
languageSettings {
121+
compilerOptions{
122+
freeCompilerArgs.add("-Xexpect-actual-classes")
123+
}
121124
// progressiveMode = true
122125
}
123126
}

core/common/src/DayOfWeek.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package kotlinx.datetime
77

8-
import kotlin.native.concurrent.*
9-
108
/**
119
* The enumeration class representing the days of the week.
1210
*/
@@ -25,8 +23,7 @@ public expect enum class DayOfWeek {
2523
*/
2624
public val DayOfWeek.isoDayNumber: Int get() = ordinal + 1
2725

28-
@SharedImmutable
29-
private val allDaysOfWeek = DayOfWeek.values().asList()
26+
private val allDaysOfWeek = DayOfWeek.entries
3027

3128
/**
3229
* Returns the [DayOfWeek] instance for the given ISO-8601 week day number. Monday is 1, Sunday is 7.

core/common/src/Month.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package kotlinx.datetime
77

8-
import kotlin.native.concurrent.*
9-
108
/**
119
* The enumeration class representing the 12 months of the year.
1210
*/
@@ -55,8 +53,7 @@ public expect enum class Month {
5553
*/
5654
public val Month.number: Int get() = ordinal + 1
5755

58-
@SharedImmutable
59-
private val allMonths = Month.values().asList()
56+
private val allMonths = Month.entries
6057

6158
/**
6259
* Returns the [Month] instance for the given month number. January is 1, December is 12.

core/linux/src/TimeZoneNative.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal actual class RegionTimeZone(private val tzid: TimeZoneRules, actual ove
2727
get() = tzdbOnFilesystem.availableTimeZoneIds()
2828
}
2929

30+
@OptIn(ExperimentalForeignApi::class)
3031
actual override fun atStartOfDay(date: LocalDate): Instant = memScoped {
3132
val ldt = LocalDateTime(date, LocalTime.MIN)
3233
when (val info = tzid.infoAtDatetime(ldt)) {
@@ -57,15 +58,16 @@ internal actual class RegionTimeZone(private val tzid: TimeZoneRules, actual ove
5758
actual override fun offsetAtImpl(instant: Instant): UtcOffset = tzid.infoAtInstant(instant)
5859
}
5960

61+
@OptIn(ExperimentalForeignApi::class)
6062
internal actual fun currentTime(): Instant = memScoped {
6163
val tm = alloc<timespec>()
6264
val error = clock_gettime(CLOCK_REALTIME, tm.ptr)
6365
if (error != 0) {
6466
val errorStr: String = strerror(errno)?.toKString() ?: "Unknown error"
6567
throw IllegalStateException("Could not obtain the current clock readings from the system: $errorStr")
6668
}
67-
val seconds: Long = tm.tv_sec
68-
val nanoseconds: Int = tm.tv_nsec.toInt()
69+
val seconds: Long = tm.tv_sec.convert<Long>()
70+
val nanoseconds: Int = tm.tv_nsec.convert<Int>()
6971
try {
7072
require(nanoseconds in 0 until NANOS_PER_ONE)
7173
return Instant(seconds, nanoseconds)
@@ -74,5 +76,4 @@ internal actual fun currentTime(): Instant = memScoped {
7476
}
7577
}
7678

77-
@ThreadLocal
7879
private val tzdbOnFilesystem = TzdbOnFilesystem(Path.fromString("/usr/share/zoneinfo"))

core/linux/test/TimeZoneRulesCompleteTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TimeZoneRulesCompleteTest {
5959
}
6060
}
6161

62+
@OptIn(ExperimentalForeignApi::class)
6263
private inline fun runUnixCommand(command: String): Sequence<String> = sequence {
6364
val pipe = popen(command, "r") ?: error("Failed to run command: $command")
6465
try {

core/nix/src/internal/filesystem.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package kotlinx.datetime.internal
88
import kotlinx.cinterop.*
99
import platform.posix.*
1010

11+
@OptIn(ExperimentalForeignApi::class)
1112
internal class Path(val isAbsolute: Boolean, val components: List<String>) {
1213
fun check(): PathInfo? = memScoped {
1314
val stat = alloc<stat>()
@@ -58,6 +59,7 @@ internal interface PathInfo {
5859
val isSymlink: Boolean
5960
}
6061

62+
@OptIn(ExperimentalForeignApi::class)
6163
internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLeadingComponents: Int = this.components.size, actionOnFile: (Path) -> Unit) {
6264
val handler = opendir(this.toString()) ?: return
6365
try {
@@ -81,7 +83,7 @@ internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLead
8183
}
8284
}
8385

84-
86+
@OptIn(ExperimentalForeignApi::class)
8587
internal fun Path.readBytes(): ByteArray {
8688
val handler = fopen(this.toString(), "rb") ?: throw RuntimeException("Cannot open file $this")
8789
try {
@@ -100,5 +102,6 @@ internal fun Path.readBytes(): ByteArray {
100102
}
101103
}
102104

105+
@OptIn(ExperimentalForeignApi::class)
103106
private val errnoString
104107
get() = strerror(errno)?.toKString() ?: "Unknown error"

0 commit comments

Comments
 (0)