summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJake Leahy <jake@leahy.dev>2023-06-26 23:07:42 +1000
committerGitHub <noreply@github.com>2023-06-26 15:07:42 +0200
commit43a3de9077955031e55691ebb84ee958f6aa260e (patch)
treea83171f9fdea667c36d18c7c7a9bcb15bfae0f61
parent3e44d5742fe7fb54d91465320ee19cb613ae0b46 (diff)
downloadNim-43a3de9077955031e55691ebb84ee958f6aa260e.tar.gz
Fix regression in `std/times` (#22155)
* Add simple test case

Just so the regression doesn't happen again

* Specify initDateTime is gcsafe in the forward declarations
-rw-r--r--lib/pure/times.nim4
-rw-r--r--tests/stdlib/ttimes.nim4
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index bea1ac760..4f7af657c 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -1529,11 +1529,11 @@ proc getClockStr*(dt = now()): string {.rtl, extern: "nt$1", tags: [TimeEffect].
 proc initDateTime*(weekday: WeekDay, isoweek: IsoWeekRange, isoyear: IsoYear,
                    hour: HourRange, minute: MinuteRange, second: SecondRange,
                    nanosecond: NanosecondRange,
-                   zone: Timezone = local()): DateTime {.raises: [], tags: [], since: (1, 5).}
+                   zone: Timezone = local()): DateTime {.gcsafe, raises: [], tags: [], since: (1, 5).}
 
 proc initDateTime*(weekday: WeekDay, isoweek: IsoWeekRange, isoyear: IsoYear,
                    hour: HourRange, minute: MinuteRange, second: SecondRange,
-                   zone: Timezone = local()): DateTime {.raises: [], tags: [], since: (1, 5).}
+                   zone: Timezone = local()): DateTime {.gcsafe, raises: [], tags: [], since: (1, 5).}
 
 #
 # TimeFormat
diff --git a/tests/stdlib/ttimes.nim b/tests/stdlib/ttimes.nim
index 5794fa739..e01ab3a4f 100644
--- a/tests/stdlib/ttimes.nim
+++ b/tests/stdlib/ttimes.nim
@@ -766,3 +766,7 @@ block: # ttimes
     check dt.format("GGGG") == "2023"
     check dt.format("dddd 'KW'V GGGG") == "Thursday KW1 2023"
 
+  block: # Can be used inside gcsafe proc
+    proc test(): DateTime {.gcsafe.} =
+      result = "1970".parse("yyyy")
+    doAssert test().year == 1970