Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
(cherry picked from commit f6f789b)
  • Loading branch information
LemonBoy authored and Clyybber committed Sep 25, 2019
1 parent 657e09e commit 1289cb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 6 additions & 7 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,7 @@ 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

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")
Expand All @@ -621,7 +617,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:
Expand All @@ -639,7 +638,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)
Expand Down
15 changes: 15 additions & 0 deletions tests/vm/teval1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ doAssert x == ""
static:
var i, j: set[int8] = {}
var k = i + j

type
Obj = object
x: int

converter toObj(x: int): Obj = Obj(x: x)

# bug #10514
block:
const
b: Obj = 42
bar = [b]

let i_runtime = 0
doAssert bar[i_runtime] == b

0 comments on commit 1289cb7

Please sign in to comment.