Skip to content

Commit

Permalink
allow generic compileTime procs?
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 16, 2024
1 parent 995081b commit 935553f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =

if callee.magic notin ctfeWhitelist: return

if callee.kind notin {skProc, skFunc, skConverter, skConst} or callee.isGenericRoutine:
if callee.kind notin {skProc, skFunc, skConverter, skConst} or
hasUnresolvedParams(n[0], {}):
return

if n.typ != nil and typeAllowed(n.typ, skConst, c) != nil: return
Expand Down
14 changes: 14 additions & 0 deletions tests/vm/tgenericcompiletimeproc.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
block: # issue #10753
proc foo(x: int): int {.compileTime.} = x
const a = foo(123)
doAssert foo(123) == a

proc bar[T](x: T): T {.compileTime.} = x
const b = bar(123)
doAssert bar(123) == b
const c = bar("abc")
doAssert bar("abc") == c

block: # issue #22021
proc foo(x: static int): int {.compileTime.} = x + 1
doAssert foo(123) == 124

0 comments on commit 935553f

Please sign in to comment.