From 3bf94fc86ee24de1cbc1f94bbab9b8105b0b9fd4 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:29:47 +0300 Subject: [PATCH] allow generic compileTime procs? fixes #10753, fixes #22021 --- compiler/semexprs.nim | 3 ++- tests/vm/tgenericcompiletimeproc.nim | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/vm/tgenericcompiletimeproc.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 6b4e27394f3dd..30c17f4cfe7df 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -914,7 +914,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 diff --git a/tests/vm/tgenericcompiletimeproc.nim b/tests/vm/tgenericcompiletimeproc.nim new file mode 100644 index 0000000000000..1e52825fb41f8 --- /dev/null +++ b/tests/vm/tgenericcompiletimeproc.nim @@ -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