disallow negative indexing

This commit is contained in:
Araq 2015-03-26 17:27:51 +01:00
commit ed0d9e271d
7 changed files with 164 additions and 148 deletions

View file

@ -135,6 +135,13 @@ proc isStrangeArray(t: PType): bool =
let t = t.skipTypes(abstractInst)
result = t.kind == tyArray and t.firstOrd != 0
proc isNegative(n: PNode): bool =
let n = n.skipConv
if n.kind in {nkCharLit..nkUInt64Lit}:
result = n.intVal < 0
elif n.kind in nkCallKinds and n.sons[0].kind == nkSym:
result = n.sons[0].sym.magic in {mUnaryMinusI, mUnaryMinusI64}
proc magicsAfterOverloadResolution(c: PContext, n: PNode,
flags: TExprFlags): PNode =
case n[0].sym.magic
@ -158,6 +165,12 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
of mProcCall:
result = n
result.typ = n[1].typ
of mDotDot:
result = n
# we only need to warnings here about negative indexing:
if isNegative(n.sons[1]) or (n.len > 2 and isNegative(n.sons[2])):
message(n.info, warnDeprecated,
"use '^' instead of '-'; negative indexing")
of mRoof:
# error correction:
result = n.sons[1]