Skip to content

Commit

Permalink
fix nim-lang#9880 index out of bounds (remaining cases); revives nim-…
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 9, 2019
1 parent 6d546fd commit e0c2bfb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## An instruction is 1-3 int32s in memory, it is a register based VM.

import ast except getstr
import system/helpers2
import system/indexerrors

import
strutils, astalgo, msgs, vmdef, vmgen, nimsets, types, passes,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/typeinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
include "system/inclrtl.nim"
include "system/hti.nim"

import system/helpers2
import system/indexerrors

{.pop.}

Expand Down
2 changes: 1 addition & 1 deletion lib/pure/collections/sharedstrings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
type
UncheckedCharArray = UncheckedArray[char]

import system/helpers2
import system/indexerrors

type
Buffer = ptr object
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
include "system/inclrtl"

import
strutils, pathnorm, system/helpers2
strutils, pathnorm, system/indexerrors

const weirdTarget = defined(nimscript) or defined(js)

Expand Down
2 changes: 1 addition & 1 deletion lib/system/jssys.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# distribution, for details about the copyright.
#

import system/helpers2
import system/indexerrors

proc log*(s: cstring) {.importc: "console.log", varargs, nodecl.}

Expand Down
41 changes: 10 additions & 31 deletions tests/exception/tindexerrorformatbounds.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import strutils

import os, osproc, strutils

const characters = "abcdefghijklmnopqrstuvwxyz"
var s: string
Expand All @@ -13,40 +11,21 @@ block:
discard s[0..999]
except IndexError:
let msg = getCurrentExceptionMsg()
let expected = "(i:$#) <= (n:$#)" % [$len(s), $(len(s)-1)]
doAssert msg.contains expected
let expected = "(i: $#) <= (n: $#)" % [$len(s), $(len(s)-1)]
doAssert msg.contains expected, $(msg, expected)

block:
try:
discard paramStr(999)
except IndexError:
let msg = getCurrentExceptionMsg()
let expected = "(i:999) <= (n:0)"
let expected = "(i: 999) <= (n: 0)"
doAssert msg.contains expected

static:
block:
const nim = getCurrentCompilerExe()

block:
let ret = gorgeEx(nim & " e testindexerroroutput.nims test1")
let expected = "(i:3) <= (n:2)"
doAssert ret.exitCode != 0
doAssert ret.output.contains expected

block:
let ret = gorgeEx(nim & " e testindexerroroutput.nims test2")
let expected = "(i:3) <= (n:2)"
doAssert ret.exitCode != 0
doAssert ret.output.contains expected

block:
let ret = gorgeEx(nim & " e testindexerroroutput.nims test3")
let expected = "(i:3) <= (n:2)"
doAssert ret.exitCode != 0
doAssert ret.output.contains expected

block:
let ret = gorgeEx(nim & " e testindexerroroutput.nims test4")
let expected = "(i:3) <= (n:2)"
doAssert ret.exitCode != 0
doAssert ret.output.contains expected
for i in 1..4:
let (outp, errC) = execCmdEx("$# e tests/exception/testindexerroroutput.nims test$#" % [nim, $i])
let expected = "(i: 3) <= (n: 2)"
doAssert errC != 0
doAssert outp.contains expected, $(outp, errC, expected, i)

0 comments on commit e0c2bfb

Please sign in to comment.