mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-23 07:45:23 +00:00
remove conditionals on nimHasUserErrors, nimNoNilSeqs2, nimNoNilSeqs (#16861)
* cleanup docs for type(nil) | type(nil); simplify nimHasUserErrors * simplify nimNoNilSeqs2 * simplify nimNoNilSeqs * fixup
This commit is contained in:
@@ -1150,10 +1150,7 @@ when (NimMajor, NimMinor) < (1, 3) and defined(js):
|
||||
|
||||
proc ssClose(s: Stream) {.compileTime.} =
|
||||
var s = StringStream(s)
|
||||
when defined(nimNoNilSeqs):
|
||||
s.data = ""
|
||||
else:
|
||||
s.data = nil
|
||||
s.data = ""
|
||||
|
||||
proc newStringStream*(s: string = ""): owned StringStream {.compileTime.} =
|
||||
new(result)
|
||||
@@ -1253,10 +1250,7 @@ else: # after 1.3 or JS not defined
|
||||
|
||||
proc ssClose(s: Stream) =
|
||||
var s = StringStream(s)
|
||||
when defined(nimNoNilSeqs):
|
||||
s.data = ""
|
||||
else:
|
||||
s.data = nil
|
||||
s.data = ""
|
||||
|
||||
proc newStringStream*(s: string = ""): owned StringStream =
|
||||
## Creates a new stream from the string `s`.
|
||||
|
||||
@@ -180,7 +180,7 @@ proc initPackedSet*[A]: PackedSet[A] =
|
||||
counter: 0,
|
||||
max: 0,
|
||||
head: nil,
|
||||
data: when defined(nimNoNilSeqs): @[] else: nil)
|
||||
data: @[])
|
||||
# a: array[0..33, int] # profiling shows that 34 elements are enough
|
||||
|
||||
proc contains*[A](s: PackedSet[A], key: A): bool =
|
||||
@@ -392,10 +392,7 @@ proc clear*[A](result: var PackedSet[A]) =
|
||||
# setLen(result.data, InitIntSetSize)
|
||||
# for i in 0..InitIntSetSize - 1: result.data[i] = nil
|
||||
# result.max = InitIntSetSize - 1
|
||||
when defined(nimNoNilSeqs):
|
||||
result.data = @[]
|
||||
else:
|
||||
result.data = nil
|
||||
result.data = @[]
|
||||
result.max = 0
|
||||
result.counter = 0
|
||||
result.head = nil
|
||||
@@ -426,10 +423,7 @@ proc assign*[A](dest: var PackedSet[A], src: PackedSet[A]) =
|
||||
assert len(a) == 2
|
||||
|
||||
if src.elems <= src.a.len:
|
||||
when defined(nimNoNilSeqs):
|
||||
dest.data = @[]
|
||||
else:
|
||||
dest.data = nil
|
||||
dest.data = @[]
|
||||
dest.max = 0
|
||||
dest.counter = src.counter
|
||||
dest.head = nil
|
||||
|
||||
@@ -1559,11 +1559,8 @@ proc len*[U: Ordinal; V: Ordinal](x: HSlice[U, V]): int {.noSideEffect, inline.}
|
||||
## assert((5..2).len == 0)
|
||||
result = max(0, ord(x.b) - ord(x.a) + 1)
|
||||
|
||||
when defined(nimNoNilSeqs2):
|
||||
when not compileOption("nilseqs"):
|
||||
{.pragma: nilError, error.}
|
||||
else:
|
||||
{.pragma: nilError.}
|
||||
when not compileOption("nilseqs"):
|
||||
{.pragma: nilError, error.}
|
||||
else:
|
||||
{.pragma: nilError.}
|
||||
|
||||
@@ -2942,19 +2939,16 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
||||
elif x.isNil or y.isNil: result = false
|
||||
else: result = strcmp(x, y) == 0
|
||||
|
||||
when defined(nimNoNilSeqs2) and not compileOption("nilseqs"):
|
||||
when defined(nimHasUserErrors):
|
||||
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)'.
|
||||
# Eventually (in 0.20?) we will be able to remove this hack completely.
|
||||
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.
|
||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||
discard
|
||||
proc `==`*(x: type(nil) | type(nil); y: string): bool {.
|
||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||
discard
|
||||
else:
|
||||
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.error.} = discard
|
||||
proc `==`*(x: type(nil) | type(nil); y: string): bool {.error.} = discard
|
||||
when not compileOption("nilseqs"):
|
||||
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)',
|
||||
# especially for converters, see tests/overload/tconverter_to_string.nim
|
||||
# Eventually we will be able to remove this hack completely.
|
||||
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.
|
||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||
discard
|
||||
proc `==`*(x: type(nil) | type(nil); y: string): bool {.
|
||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||
discard
|
||||
|
||||
template closureScope*(body: untyped): untyped =
|
||||
## Useful when creating a closure in a loop to capture local loop variables by
|
||||
|
||||
Reference in New Issue
Block a user