diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a4f4c5927a..60a9c56f9c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1006,9 +1006,9 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = n.typ.flags.incl tfUnresolved # optimization pass: not necessary for correctness of the semantic pass - if callee.kind == skConst or + if (callee.kind == skConst or {sfNoSideEffect, sfCompileTime} * callee.flags != {} and - {sfForward, sfImportc} * callee.flags == {} and n.typ != nil: + {sfForward, sfImportc} * callee.flags == {}) and n.typ != nil: if callee.kind != skConst and sfCompileTime notin callee.flags and diff --git a/tests/vm/tconstprocassignments.nim b/tests/vm/tconstprocassignments.nim index 0e2d2ed165..d38872104e 100644 --- a/tests/vm/tconstprocassignments.nim +++ b/tests/vm/tconstprocassignments.nim @@ -16,3 +16,18 @@ const G = proc ():int = y() echo G() + + +block: # bug #24359 + block: + proc h(_: bool) = discard + const m = h + static: m(true) # works + m(true) # does not work + +block: + block: + proc h(_: bool): int = result = 1 + const m = h + static: doAssert m(true) == 1 # works + doAssert m(true) == 1 # does not work