summary refs log tree commit diff stats
path: root/tests/discard/tdiscardable.nim
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-07-02 14:49:37 +0800
committerGitHub <noreply@github.com>2024-07-02 08:49:37 +0200
commitfe3039410f9fa637fdd958df4d96272484ebdb86 (patch)
treed09e2a3a749bff15108473c5be4cae582384b31d /tests/discard/tdiscardable.nim
parent96aba18963cbcf87250f93b453122d411aeb1d17 (diff)
downloadNim-fe3039410f9fa637fdd958df4d96272484ebdb86.tar.gz
fixes #23775; injectdestructors now handles discardable statements (#23780)
fixes #23775
Diffstat (limited to 'tests/discard/tdiscardable.nim')
-rw-r--r--tests/discard/tdiscardable.nim24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/discard/tdiscardable.nim b/tests/discard/tdiscardable.nim
index 5988f5949..31020251f 100644
--- a/tests/discard/tdiscardable.nim
+++ b/tests/discard/tdiscardable.nim
@@ -140,3 +140,27 @@ block: # issue #14665
         continue
       inc i
   test()
+
+block: # bug #23775
+  proc retInt(): int {.discardable.} =
+    42
+
+  proc retString(): string {.discardable.} =
+    "text"
+
+  type
+    Enum = enum
+      A, B, C, D
+
+  proc doStuff(msg: Enum) =
+    case msg:
+    of A:
+      retString()
+    of B:
+      retInt()
+    of C:
+      discard retString()
+    else:
+      let _ = retString()
+
+  doStuff(C)