summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/semstmts.nim')
-rwxr-xr-xcompiler/semstmts.nim15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 0a3daf79c..624b8f196 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -337,14 +337,23 @@ proc semConst(c: PContext, n: PNode): PNode =
     var v = semIdentDef(c, a.sons[0], skConst)
     var typ: PType = nil
     if a.sons[1].kind != nkEmpty: typ = semTypeNode(c, a.sons[1], nil)
-    var def = semAndEvalConstExpr(c, a.sons[2]) 
-    # check type compability between def.typ and typ:
+
+    var e = semExprWithType(c, a.sons[2])
+    if e == nil: GlobalError(a.sons[2].info, errConstExprExpected)
+    var def = getConstExpr(c.module, e)
+    if def == nil: 
+      v.flags.incl(sfFakeConst)
+      def = evalConstExpr(c.module, e)
+      if def == nil or def.kind == nkEmpty: def = e
+    # check type compatibility between def.typ and typ:
     if typ != nil:
       def = fitRemoveHiddenConv(c, typ, def)
     else:
       typ = def.typ
     if not typeAllowed(typ, skConst):
-      GlobalError(a.info, errXisNoType, typeToString(typ))
+      v.flags.incl(sfFakeConst)
+      if not typeAllowed(typ, skVar):
+        GlobalError(a.info, errXisNoType, typeToString(typ))
     v.typ = typ
     v.ast = def               # no need to copy
     if v.flags * {sfStar, sfMinus} != {}: incl(v.flags, sfInInterface)