From cc2be5e4c69fe655ae8546040ed1ed79fa41d055 Mon Sep 17 00:00:00 2001 From: Aditya Siram Date: Sat, 4 May 2019 15:57:16 -0500 Subject: [PATCH] Fixes #11045. Assigning a proc to const and invoking. (#11076) --- compiler/semexprs.nim | 12 ++++++++---- tests/vm/tconstprocassignments.nim | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 tests/vm/tconstprocassignments.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index ead9dab27c..0d81cab372 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -709,13 +709,17 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = n.typ.flags.incl tfUnresolved # optimization pass: not necessary for correctness of the semantic pass - if {sfNoSideEffect, sfCompileTime} * callee.flags != {} and + if callee.kind == skConst or + {sfNoSideEffect, sfCompileTime} * callee.flags != {} and {sfForward, sfImportc} * callee.flags == {} and n.typ != nil: - if sfCompileTime notin callee.flags and - optImplicitStatic notin c.config.options: return + + if callee.kind != skConst and + sfCompileTime notin callee.flags and + optImplicitStatic notin c.config.options: return if callee.magic notin ctfeWhitelist: return - if callee.kind notin {skProc, skFunc, skConverter} or callee.isGenericRoutine: + + if callee.kind notin {skProc, skFunc, skConverter, skConst} or callee.isGenericRoutine: return if n.typ != nil and typeAllowed(n.typ, skConst) != nil: return diff --git a/tests/vm/tconstprocassignments.nim b/tests/vm/tconstprocassignments.nim new file mode 100644 index 0000000000..0e2d2ed165 --- /dev/null +++ b/tests/vm/tconstprocassignments.nim @@ -0,0 +1,18 @@ +discard """ + output: ''' +100 +100 +''' +""" + +proc f():int {.compileTime.} = 100 + +const F = f +echo F() + +const G = proc ():int = + let x = f + let y = x + y() + +echo G()