diff --git a/compiler/semmacrosanity.nim b/compiler/semmacrosanity.nim index 02c56c0354..3056f5d721 100644 --- a/compiler/semmacrosanity.nim +++ b/compiler/semmacrosanity.nim @@ -88,7 +88,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) = else: globalError(conf, n.info, "string literal must be of some string type") of nkNilLit: - if x.kind in NilableTypes: + if x.kind in NilableTypes+{tyString, tySequence}: n.typ = t else: globalError(conf, n.info, "nil literal must be of some pointer type") diff --git a/lib/system.nim b/lib/system.nim index 4b69a80673..c730167ede 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2344,8 +2344,12 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} = ## Generic equals operator for sequences: relies on a equals operator for ## the element type `T`. when nimvm: - if x.isNil and y.isNil: - return true + when not defined(nimNoNil): + if x.isNil and y.isNil: + return true + else: + if x.len == 0 and y.len == 0: + return true else: when not defined(JS): proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} = diff --git a/tests/cpp/tasync_cpp.nim b/tests/cpp/tasync_cpp.nim index a5e3374b6a..50bc1853ce 100644 --- a/tests/cpp/tasync_cpp.nim +++ b/tests/cpp/tasync_cpp.nim @@ -1,6 +1,7 @@ discard """ targets: "cpp" output: "hello" + cmd: "nim cpp --nilseqs:on $file" """ # bug #3299 diff --git a/tests/distinct/tnil.nim b/tests/distinct/tnil.nim index 759a14657a..16de38f603 100644 --- a/tests/distinct/tnil.nim +++ b/tests/distinct/tnil.nim @@ -9,7 +9,6 @@ discard """ type MyPointer = distinct pointer MyString = distinct string - MyStringNotNil = distinct (string not nil) MyInt = distinct int proc foo(a: MyPointer) = @@ -26,20 +25,6 @@ p = cast[MyPointer](nil) p = nil.MyPointer p = nil -var c: MyString -c = "Test".MyString -c = nil.MyString -c = nil - -p = nil -doAssert(compiles(c = p) == false) - -var n: MyStringNotNil = "Test".MyStringNotNil # Cannot prove warning ... -n = "Test".MyStringNotNil -doAssert(compiles(n = nil.MyStringNotNil) == false) -doAssert(compiles(n = nil.MyStringNotNil) == false) -doAssert(compiles(n = nil) == false) - var i: MyInt i = 1.MyInt doAssert(compiles(i = nil) == false) diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim index a32c6c7ecd..d09dda0575 100644 --- a/tests/notnil/tmust_compile.nim +++ b/tests/notnil/tmust_compile.nim @@ -44,16 +44,16 @@ import json type foo = object - thing: string not nil + thing: ptr int not nil CTS = ref object subs_by_sid: Table[int, foo] proc parse(cts: CTS, jn: JsonNode) = - + var y = jn.getInt(4523) let ces = foo( - thing: jn.getStr("thing") + thing: addr y ) cts.subs_by_sid[0] = ces @@ -63,17 +63,3 @@ proc parse(cts: CTS, jn: JsonNode) = proc p(x: proc(){.closure.} not nil) = discard p(proc(){.closure.} = discard) - -# bug #3993 - -type - List[T] = seq[T] not nil - -proc `^^`[T](v: T, lst: List[T]): List[T] = - result = @[v] - result.add(lst) - -proc Nil[T](): List[T] = @[] - -when isMainModule: - let lst = 1 ^^ 2 ^^ Nil[int]() diff --git a/tests/notnil/tnotnil1.nim b/tests/notnil/tnotnil1.nim index 7f9d022958..60666d64d4 100644 --- a/tests/notnil/tnotnil1.nim +++ b/tests/notnil/tnotnil1.nim @@ -1,6 +1,6 @@ discard """ errormsg: "'y' is provably nil" - line:38 + line:25 """ import strutils @@ -10,19 +10,6 @@ type TObj = object x, y: int -type - superstring = string not nil - - -proc q(s: superstring) = - echo s - -proc p2() = - var a: string = "I am not nil" - q(a) # but this should and does not - -p2() - proc q(x: pointer not nil) = discard diff --git a/tests/notnil/tnotnil_in_objconstr.nim b/tests/notnil/tnotnil_in_objconstr.nim index d33709906b..f0d5c1ae20 100644 --- a/tests/notnil/tnotnil_in_objconstr.nim +++ b/tests/notnil/tnotnil_in_objconstr.nim @@ -6,9 +6,9 @@ discard """ # bug #2355 type Foo = object - foo: string not nil - bar: string not nil - + foo: ref int + bar: ref int not nil +var x: ref int = new(int) # Create instance without initializaing the `bar` field -var f = Foo(foo: "foo") +var f = Foo(foo: x) echo f.bar.isNil # true diff --git a/tests/vm/tseq_badinit.nim b/tests/vm/tseq_badinit.nim index 15889d60ec..5fa223c85b 100644 --- a/tests/vm/tseq_badinit.nim +++ b/tests/vm/tseq_badinit.nim @@ -22,14 +22,14 @@ template test(typename, default: untyped) = result = newSeq[typename]() result.add(default) result.setLen(3) - for i in 0 .. <2: + for i in 0 ..< 2: result[i] = default const constval = `abc typename`() doAssert(constval == `abc typename`()) proc `arr typename`(): array[4, typename] = - for i in 0 .. <2: + for i in 0 ..< 2: result[i] = default const constarr = `arr typename`() doAssert(constarr == `arr typename`())