summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2019-09-28 19:50:20 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-09-28 19:50:20 +0200
commit85db42ad8c1a19ea47bd5826d8639e8974cc9042 (patch)
tree5d00473b4dbf1caeacddcc8a0b14467523c5e630 /compiler
parent5a65243e14773fc0d96bfd70429056dc5161df7f (diff)
downloadNim-85db42ad8c1a19ea47bd5826d8639e8974cc9042.tar.gz
Fixes #10514 (#12268)
* Fixes #10514

(cherry picked from commit f6f789bb4db2a367384ba6ad75706edd503de1f8)

* Add comment

* Add changelog entry
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semstmts.nim14
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 512dbca68..8acc5ce2f 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -595,11 +595,8 @@ proc semConst(c: PContext, n: PNode): PNode =
     if a.sons[length-2].kind != nkEmpty:
       typ = semTypeNode(c, a.sons[length-2], nil)
 
-    var def = semConstExpr(c, a.sons[length-1])
-    if def == nil:
-      localError(c.config, a.sons[length-1].info, errConstExprExpected)
-      continue
-
+    # don't evaluate here since the type compatibility check below may add a converter
+    var def = semExprWithType(c, a[^1])
     if def.typ.kind == tyProc and def.kind == nkSym:
       if def.sym.kind == skMacro:
         localError(c.config, def.info, errCannotAssignMacroSymbol % "constant")
@@ -621,7 +618,10 @@ proc semConst(c: PContext, n: PNode): PNode =
         def = fitRemoveHiddenConv(c, typ, def)
     else:
       typ = def.typ
-    if typ == nil:
+
+    # evaluate the node
+    def = semConstExpr(c, def)
+    if def == nil:
       localError(c.config, a.sons[length-1].info, errConstExprExpected)
       continue
     if typeAllowed(typ, skConst) != nil and def.kind != nkNilLit:
@@ -639,7 +639,7 @@ proc semConst(c: PContext, n: PNode): PNode =
       b.sons[length-2] = a.sons[length-2]
       b.sons[length-1] = def
 
-    for j in 0 .. length-3:
+    for j in 0 ..< length-2:
       var v = semIdentDef(c, a.sons[j], skConst)
       if sfGenSym notin v.flags: addInterfaceDecl(c, v)
       elif v.owner == nil: v.owner = getCurrOwner(c)
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245