diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semtypes.nim | 12 | ||||
-rw-r--r-- | compiler/vmgen.nim | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index c53dc0f7d..e8dcea731 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -225,8 +225,18 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = # properly filled-out in semtypinst (see how tyStaticExpr # is handled there). indx = makeRangeWithStaticExpr(c, e) - else: + elif e.kind == nkIdent: indx = e.typ.skipTypes({tyTypeDesc}) + else: + let x = semConstExpr(c, e) + if x.kind in {nkIntLit..nkUInt64Lit}: + indx = makeRangeType(c, 0, x.intVal-1, n.info, + x.typ.skipTypes({tyTypeDesc})) + else: + indx = x.typ.skipTypes({tyTypeDesc}) + if not isOrdinalType(indx): + localError(n[1].info, errOrdinalTypeExpected) + #localError(n[1].info, errConstExprExpected) addSonSkipIntLit(result, indx) if indx.kind == tyGenericInst: indx = lastSon(indx) if indx.kind notin {tyGenericParam, tyStatic, tyFromExpr}: diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 434cb0932..7c0c3d4f5 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1501,7 +1501,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) = else: localError(n.info, errGenerated, "VM is not allowed to 'cast'") else: - internalError n.info, "too implement " & $n.kind + internalError n.info, "cannot generate VM code for " & n.renderTree proc removeLastEof(c: PCtx) = let last = c.code.len-1 |