mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
replace doAssert false with raiseAssert in lib, which works better with strictdefs (#22458)
This commit is contained in:
@@ -460,7 +460,7 @@ template `=~` *(s: string, pattern: Regex): untyped =
|
||||
elif line =~ re"\s*(\#.*)": # matches a comment
|
||||
# note that the implicit `matches` array is different from 1st branch
|
||||
result = $(matches[0],)
|
||||
else: doAssert false
|
||||
else: raiseAssert "unreachable"
|
||||
doAssert not declared(matches)
|
||||
doAssert parse("NAME = LENA") == """("NAME", "LENA")"""
|
||||
doAssert parse(" # comment ... ") == """("# comment ... ",)"""
|
||||
|
||||
@@ -1423,7 +1423,7 @@ when defined(nodejs):
|
||||
parent.childNodes[i] = newNode
|
||||
return
|
||||
inc i
|
||||
doAssert false, "old node not in node list"
|
||||
raiseAssert "old node not in node list"
|
||||
|
||||
proc removeChild*(parent, child: Node) =
|
||||
child.parentNode = nil
|
||||
@@ -1433,7 +1433,7 @@ when defined(nodejs):
|
||||
parent.childNodes.delete(i)
|
||||
return
|
||||
inc i
|
||||
doAssert false, "old node not in node list"
|
||||
raiseAssert "old node not in node list"
|
||||
|
||||
proc insertBefore*(parent, newNode, before: Node) =
|
||||
appendChild(parent, newNode)
|
||||
@@ -1445,7 +1445,7 @@ when defined(nodejs):
|
||||
parent.childNodes[i-1] = newNode
|
||||
return
|
||||
inc i
|
||||
#doAssert false, "before not in node list"
|
||||
#raiseAssert "before not in node list"
|
||||
|
||||
proc createElement*(d: Document, identifier: cstring): Element =
|
||||
new(result)
|
||||
|
||||
@@ -1175,7 +1175,7 @@ proc renderRstToOut(d: PDoc, n: PRstNode, result: var string) =
|
||||
renderAux(d, n, "<div class=\"option-list-description\">$1</div>",
|
||||
" $1\n", result)
|
||||
of rnOption, rnOptionString, rnOptionArgument:
|
||||
doAssert false, "renderRstToOut"
|
||||
raiseAssert "renderRstToOut"
|
||||
of rnLiteralBlock:
|
||||
renderAux(d, n, "<pre$2>$1</pre>\n",
|
||||
"\n\n$2\\begin{rstpre}\n$1\n\\end{rstpre}\n\n", result)
|
||||
|
||||
@@ -224,7 +224,7 @@ proc switchTo(current, to: CoroutinePtr) =
|
||||
elif to.state == CORO_CREATED:
|
||||
# Coroutine is started.
|
||||
coroExecWithStack(runCurrentTask, to.stack.bottom)
|
||||
#doAssert false
|
||||
#raiseAssert "unreachable"
|
||||
else:
|
||||
{.error: "Invalid coroutine backend set.".}
|
||||
# Execution was just resumed. Restore frame information and set active stack.
|
||||
@@ -266,7 +266,7 @@ proc runCurrentTask() =
|
||||
current.state = CORO_FINISHED
|
||||
nimGC_setStackBottom(ctx.ncbottom)
|
||||
suspend(0) # Exit coroutine without returning from coroExecWithStack()
|
||||
doAssert false
|
||||
raiseAssert "unreachable"
|
||||
|
||||
proc start*(c: proc(), stacksize: int = defaultStackSize): CoroutineRef {.discardable.} =
|
||||
## Schedule coroutine for execution. It does not run immediately.
|
||||
|
||||
@@ -368,16 +368,16 @@ proc murmurHash(x: openArray[byte]): Hash =
|
||||
return cast[Hash](h1)
|
||||
|
||||
proc hashVmImpl(x: cstring, sPos, ePos: int): Hash =
|
||||
doAssert false, "implementation override in compiler/vmops.nim"
|
||||
raiseAssert "implementation override in compiler/vmops.nim"
|
||||
|
||||
proc hashVmImpl(x: string, sPos, ePos: int): Hash =
|
||||
doAssert false, "implementation override in compiler/vmops.nim"
|
||||
raiseAssert "implementation override in compiler/vmops.nim"
|
||||
|
||||
proc hashVmImplChar(x: openArray[char], sPos, ePos: int): Hash =
|
||||
doAssert false, "implementation override in compiler/vmops.nim"
|
||||
raiseAssert "implementation override in compiler/vmops.nim"
|
||||
|
||||
proc hashVmImplByte(x: openArray[byte], sPos, ePos: int): Hash =
|
||||
doAssert false, "implementation override in compiler/vmops.nim"
|
||||
raiseAssert "implementation override in compiler/vmops.nim"
|
||||
|
||||
proc hash*(x: string): Hash =
|
||||
## Efficient hashing of strings.
|
||||
|
||||
@@ -1348,7 +1348,7 @@ elif not defined(useNimRtl):
|
||||
p.exitStatus = status
|
||||
break
|
||||
else:
|
||||
doAssert false, "unreachable!"
|
||||
raiseAssert "unreachable!"
|
||||
|
||||
result = exitStatusLikeShell(p.exitStatus)
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {},
|
||||
else:
|
||||
# we cannot provide this for NimRtl creation on Posix, because we can't
|
||||
# access the command line arguments then!
|
||||
doAssert false, "empty command line given but" &
|
||||
raiseAssert "empty command line given but" &
|
||||
" real command line is not accessible"
|
||||
result.kind = cmdEnd
|
||||
result.key = ""
|
||||
|
||||
@@ -1530,7 +1530,7 @@ when false:
|
||||
of fmReadWrite: flags = O_RDWR or int(O_CREAT)
|
||||
of fmReadWriteExisting: flags = O_RDWR
|
||||
of fmAppend: flags = O_WRONLY or int(O_CREAT) or O_APPEND
|
||||
static: doAssert false # handle bug #17888
|
||||
static: raiseAssert "unreachable" # handle bug #17888
|
||||
var handle = open(filename, flags)
|
||||
if handle < 0: raise newEOS("posix.open() call failed")
|
||||
result = newFileHandleStream(handle)
|
||||
|
||||
@@ -663,7 +663,7 @@ proc strformatImpl(f: string; openChar, closeChar: char,
|
||||
strlit.add closeChar
|
||||
inc i, 2
|
||||
else:
|
||||
doAssert false, "invalid format string: '$1' instead of '$1$1'" % $closeChar
|
||||
raiseAssert "invalid format string: '$1' instead of '$1$1'" % $closeChar
|
||||
inc i
|
||||
else:
|
||||
strlit.add f[i]
|
||||
|
||||
@@ -2089,7 +2089,7 @@ proc parsePattern(input: string, pattern: FormatPattern, i: var int,
|
||||
i.inc 2
|
||||
else:
|
||||
result = false
|
||||
of Lit: doAssert false, "Can't happen"
|
||||
of Lit: raiseAssert "Can't happen"
|
||||
|
||||
proc toDateTime(p: ParsedTime, zone: Timezone, f: TimeFormat,
|
||||
input: string): DateTime =
|
||||
|
||||
@@ -225,7 +225,7 @@ macro genericParamsImpl(T: typedesc): untyped =
|
||||
case ai.typeKind
|
||||
of ntyTypeDesc:
|
||||
ret = ai
|
||||
of ntyStatic: doAssert false
|
||||
of ntyStatic: raiseAssert "unreachable"
|
||||
else:
|
||||
# getType from a resolved symbol might return a typedesc symbol.
|
||||
# If so, use it directly instead of wrapping it in StaticParam.
|
||||
|
||||
@@ -235,7 +235,7 @@ proc colorOutput(): bool =
|
||||
else: result = false
|
||||
of "on": result = true
|
||||
of "off": result = false
|
||||
else: doAssert false, $color
|
||||
else: raiseAssert $color
|
||||
|
||||
when declared(stdout):
|
||||
if existsEnv("NIMTEST_COLOR"):
|
||||
|
||||
@@ -86,7 +86,7 @@ proc writeFloatToBuffer*(buf: var array[65, char]; value: BiggestFloat | float32
|
||||
|
||||
proc addFloatRoundtrip*(result: var string; x: float | float32) =
|
||||
when nimvm:
|
||||
doAssert false
|
||||
raiseAssert "unreachable"
|
||||
else:
|
||||
var buffer {.noinit.}: array[65, char]
|
||||
let n = writeFloatToBufferRoundtrip(buffer, x)
|
||||
@@ -94,7 +94,7 @@ proc addFloatRoundtrip*(result: var string; x: float | float32) =
|
||||
|
||||
proc addFloatSprintf*(result: var string; x: float) =
|
||||
when nimvm:
|
||||
doAssert false
|
||||
raiseAssert "unreachable"
|
||||
else:
|
||||
var buffer {.noinit.}: array[65, char]
|
||||
let n = writeFloatToBufferSprintf(buffer, x)
|
||||
|
||||
@@ -24,7 +24,7 @@ macro genAstOpt*(options: static set[GenAstOpt], args: varargs[untyped]): untype
|
||||
result = genAst(cond, s = repr(cond), lhs = cond[1], rhs = cond[2]):
|
||||
# each local symbol we access must be explicitly captured
|
||||
if not cond:
|
||||
doAssert false, "'$#'' failed: lhs: '$#', rhs: '$#'" % [s, $lhs, $rhs]
|
||||
raiseAssert "'$#'' failed: lhs: '$#', rhs: '$#'" % [s, $lhs, $rhs]
|
||||
let a = 3
|
||||
check2 a*2 == a+3
|
||||
if false: check2 a*2 < a+1 # would error with: 'a * 2 < a + 1'' failed: lhs: '6', rhs: '4'
|
||||
|
||||
@@ -14,7 +14,7 @@ func big*(integer: SomeInteger): JsBigInt {.importjs: "BigInt(#)".} =
|
||||
runnableExamples:
|
||||
doAssert big(1234567890) == big"1234567890"
|
||||
doAssert 0b1111100111.big == 0o1747.big and 0o1747.big == 999.big
|
||||
when nimvm: doAssert false, "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
when nimvm: raiseAssert "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
|
||||
func `'big`*(num: cstring): JsBigInt {.importjs: "BigInt(#)".} =
|
||||
## Constructor for `JsBigInt`.
|
||||
@@ -28,11 +28,11 @@ func `'big`*(num: cstring): JsBigInt {.importjs: "BigInt(#)".} =
|
||||
doAssert 0xdeadbeaf'big == 0xdeadbeaf.big
|
||||
doAssert 0xffffffffffffffff'big == (1'big shl 64'big) - 1'big
|
||||
doAssert not compiles(static(12'big))
|
||||
when nimvm: doAssert false, "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
when nimvm: raiseAssert "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
|
||||
func big*(integer: cstring): JsBigInt {.importjs: "BigInt(#)".} =
|
||||
## Alias for `'big`
|
||||
when nimvm: doAssert false, "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
when nimvm: raiseAssert "JsBigInt can not be used at compile-time nor static context" else: discard
|
||||
|
||||
func toCstring*(this: JsBigInt; radix: 2..36): cstring {.importjs: "#.toString(#)".} =
|
||||
## Converts from `JsBigInt` to `cstring` representation.
|
||||
|
||||
@@ -95,7 +95,7 @@ macro getDiscriminants(a: typedesc): seq[string] =
|
||||
result = quote do:
|
||||
seq[string].default
|
||||
else:
|
||||
doAssert false, "unexpected kind: " & $t2.kind
|
||||
raiseAssert "unexpected kind: " & $t2.kind
|
||||
|
||||
macro initCaseObject(T: typedesc, fun: untyped): untyped =
|
||||
## does the minimum to construct a valid case object, only initializing
|
||||
@@ -109,7 +109,7 @@ macro initCaseObject(T: typedesc, fun: untyped): untyped =
|
||||
case t.kind
|
||||
of nnkObjectTy: t2 = t[2]
|
||||
of nnkRefTy: t2 = t[0].getTypeImpl[2]
|
||||
else: doAssert false, $t.kind # xxx `nnkPtrTy` could be handled too
|
||||
else: raiseAssert $t.kind # xxx `nnkPtrTy` could be handled too
|
||||
doAssert t2.kind == nnkRecList
|
||||
result = newTree(nnkObjConstr)
|
||||
result.add sym
|
||||
@@ -289,7 +289,7 @@ proc fromJson*[T](a: var T, b: JsonNode, opt = Joptions()) =
|
||||
i.inc
|
||||
else:
|
||||
# checkJson not appropriate here
|
||||
static: doAssert false, "not yet implemented: " & $T
|
||||
static: raiseAssert "not yet implemented: " & $T
|
||||
|
||||
proc jsonTo*(b: JsonNode, T: typedesc, opt = Joptions()): T =
|
||||
## reverse of `toJson`
|
||||
|
||||
@@ -60,7 +60,7 @@ proc nativeToUnixPath*(path: string): string =
|
||||
result[0] = '/'
|
||||
result[1] = path[0]
|
||||
if path.len > 2 and path[2] != '\\':
|
||||
doAssert false, "paths like `C:foo` are currently unsupported, path: " & path
|
||||
raiseAssert "paths like `C:foo` are currently unsupported, path: " & path
|
||||
when DirSep == '\\':
|
||||
result = replace(result, '\\', '/')
|
||||
|
||||
|
||||
@@ -396,7 +396,7 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
|
||||
if not tryMoveFSObject(source, dest, isDir = false):
|
||||
when defined(windows):
|
||||
doAssert false
|
||||
raiseAssert "unreachable"
|
||||
else:
|
||||
# Fallback to copy & del
|
||||
copyFile(source, dest, {cfSymlinkAsIs})
|
||||
|
||||
@@ -259,7 +259,7 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1", raise
|
||||
# This works around the problem for posix, but Windows is still broken with nim js -d:nodejs
|
||||
result = path[0] == '/'
|
||||
else:
|
||||
doAssert false # if ever hits here, adapt as needed
|
||||
raiseAssert "unreachable" # if ever hits here, adapt as needed
|
||||
|
||||
when FileSystemCaseSensitive:
|
||||
template `!=?`(a, b: char): bool = a != b
|
||||
@@ -859,7 +859,7 @@ when not defined(nimscript):
|
||||
{.emit: "`ret` = process.cwd();".}
|
||||
return $ret
|
||||
elif defined(js):
|
||||
doAssert false, "use -d:nodejs to have `getCurrentDir` defined"
|
||||
raiseAssert "use -d:nodejs to have `getCurrentDir` defined"
|
||||
elif defined(windows):
|
||||
var bufsize = MAX_PATH.int32
|
||||
var res = newWideCString("", bufsize)
|
||||
|
||||
@@ -192,7 +192,7 @@ elif defined(linux) and not defined(nimNoGetRandom) and not defined(emscripten):
|
||||
while result < size:
|
||||
let readBytes = syscall(SYS_getrandom, addr dest[result], cint(size - result), 0).int
|
||||
if readBytes == 0:
|
||||
doAssert false
|
||||
raiseAssert "unreachable"
|
||||
elif readBytes > 0:
|
||||
inc(result, readBytes)
|
||||
else:
|
||||
|
||||
@@ -2289,7 +2289,7 @@ elif defined(nimdoc):
|
||||
## `quit(int(0x100000000))` is equal to `quit(127)` on Linux.
|
||||
##
|
||||
## .. danger:: In almost all cases, in particular in library code, prefer
|
||||
## alternatives, e.g. `doAssert false` or raise a `Defect`.
|
||||
## alternatives, e.g. `raiseAssert` or raise a `Defect`.
|
||||
## `quit` bypasses regular control flow in particular `defer`,
|
||||
## `try`, `catch`, `finally` and `destructors`, and exceptions that may have been
|
||||
## raised by an `addExitProc` proc, as well as cleanup code in other threads.
|
||||
|
||||
@@ -48,7 +48,7 @@ proc splitTestFile*(file: string): tuple[cat: string, path: string] =
|
||||
else:
|
||||
result.path = file
|
||||
return result
|
||||
doAssert false, "file must match this pattern: '/pathto/tests/dir/**/tfile.nim', got: '" & file & "'"
|
||||
raiseAssert "file must match this pattern: '/pathto/tests/dir/**/tfile.nim', got: '" & file & "'"
|
||||
|
||||
static:
|
||||
# sanity check
|
||||
|
||||
Reference in New Issue
Block a user