From 5ecc461a944b54a516e6f81df4bd6db95a86e682 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Thu, 29 Jan 2015 04:40:27 -0600 Subject: [PATCH] Fixes #2030 --- compiler/semexprs.nim | 2 +- compiler/semfold.nim | 4 ++-- tests/exprs/thighCString.nim | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 tests/exprs/thighCString.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 6638848df8..34a9cd1dd8 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -306,7 +306,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode = var typ = skipTypes(n.sons[1].typ, abstractVarRange + {tyTypeDesc, tyFieldAccessor}) case typ.kind - of tySequence, tyString, tyOpenArray, tyVarargs: + of tySequence, tyString, tyCString, tyOpenArray, tyVarargs: n.typ = getSysType(tyInt) of tyArrayConstr, tyArray: n.typ = typ.sons[0] # indextype diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 1988c512e6..a3f1b1c130 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -665,8 +665,8 @@ proc getConstExpr(m: PSym, n: PNode): PNode = of mLow: result = newIntNodeT(firstOrd(n.sons[1].typ), n) of mHigh: - if skipTypes(n.sons[1].typ, abstractVar).kind notin - {tyOpenArray, tyVarargs, tySequence, tyString}: + if skipTypes(n.sons[1].typ, abstractVar).kind notin + {tySequence, tyString, tyCString, tyOpenArray, tyVarargs}: result = newIntNodeT(lastOrd(skipTypes(n[1].typ, abstractVar)), n) else: var a = getArrayConstr(m, n.sons[1]) diff --git a/tests/exprs/thighCString.nim b/tests/exprs/thighCString.nim new file mode 100644 index 0000000000..543966df46 --- /dev/null +++ b/tests/exprs/thighCString.nim @@ -0,0 +1,6 @@ +discard """ + output: "5" +""" +let test = cstring("foobar") + +echo high(test)