mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
replace doAssert false with raiseAssert in lib, which works better with strictdefs (#22458)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user