summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-09-08 23:50:30 +0300
committerGitHub <noreply@github.com>2024-09-08 22:50:30 +0200
commit79a65da22a56eaeafce24b7c08c9d7db017173ac (patch)
tree76eb68b5a9fc60060364dd72c88072f28d081d1b /tests
parent29a7d60acbf7c4d74844884acc462fbd35cf5708 (diff)
downloadNim-79a65da22a56eaeafce24b7c08c9d7db017173ac.tar.gz
fix CI, sem whole `when` stmts as generic stmt (#24072)
fixes CI, refs #24066, refs #24065

The combination of #24065 and #24066 caused a CI failure where a `when`
branch that was never compiled gave an undeclared identifier error. This
is because the `when` branch was being semchecked with `semGenericStmt`
without `withinMixin`, which is the flag `semgnrc` normally gives to
`when` branch bodies. To fix this, just pass the whole `when` stmt to
`semGenericStmt` rather than the individual blocks.

The alternative would be to just replace the calls to `semGenericStmt`
with a new proc that does the same thing, just with the flags
`{withinMixin}`.
Diffstat (limited to 'tests')
-rw-r--r--tests/proc/tstaticsignature.nim15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/proc/tstaticsignature.nim b/tests/proc/tstaticsignature.nim
index 3c6d66b2b..518c88ba5 100644
--- a/tests/proc/tstaticsignature.nim
+++ b/tests/proc/tstaticsignature.nim
@@ -235,3 +235,18 @@ block: # issue #22607, needs nkWhenStmt to be handled like nkRecWhen
   test[true](1.int)
   test[false](1.0)
   doAssert not compiles(test[])
+
+block: # `when` in static signature
+  template ctAnd(a, b): bool =
+    when a:
+      when b: true
+      else: false
+    else: false
+  template test(): untyped =
+    when ctAnd(declared(SharedTable), typeof(result) is SharedTable):
+      result = SharedTable()
+    else:
+      result = 123
+  proc foo[T](): T = test()
+  proc bar[T](x = foo[T]()): T = x
+  doAssert bar[int]() == 123