make tests green again
This commit is contained in:
parent
a0cde8cee6
commit
f91a181f58
8 changed files with 18 additions and 55 deletions
|
|
@ -88,7 +88,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
|
||||||
else:
|
else:
|
||||||
globalError(conf, n.info, "string literal must be of some string type")
|
globalError(conf, n.info, "string literal must be of some string type")
|
||||||
of nkNilLit:
|
of nkNilLit:
|
||||||
if x.kind in NilableTypes:
|
if x.kind in NilableTypes+{tyString, tySequence}:
|
||||||
n.typ = t
|
n.typ = t
|
||||||
else:
|
else:
|
||||||
globalError(conf, n.info, "nil literal must be of some pointer type")
|
globalError(conf, n.info, "nil literal must be of some pointer type")
|
||||||
|
|
|
||||||
|
|
@ -2344,8 +2344,12 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
|
||||||
## Generic equals operator for sequences: relies on a equals operator for
|
## Generic equals operator for sequences: relies on a equals operator for
|
||||||
## the element type `T`.
|
## the element type `T`.
|
||||||
when nimvm:
|
when nimvm:
|
||||||
|
when not defined(nimNoNil):
|
||||||
if x.isNil and y.isNil:
|
if x.isNil and y.isNil:
|
||||||
return true
|
return true
|
||||||
|
else:
|
||||||
|
if x.len == 0 and y.len == 0:
|
||||||
|
return true
|
||||||
else:
|
else:
|
||||||
when not defined(JS):
|
when not defined(JS):
|
||||||
proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} =
|
proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
targets: "cpp"
|
targets: "cpp"
|
||||||
output: "hello"
|
output: "hello"
|
||||||
|
cmd: "nim cpp --nilseqs:on $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bug #3299
|
# bug #3299
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ discard """
|
||||||
type
|
type
|
||||||
MyPointer = distinct pointer
|
MyPointer = distinct pointer
|
||||||
MyString = distinct string
|
MyString = distinct string
|
||||||
MyStringNotNil = distinct (string not nil)
|
|
||||||
MyInt = distinct int
|
MyInt = distinct int
|
||||||
|
|
||||||
proc foo(a: MyPointer) =
|
proc foo(a: MyPointer) =
|
||||||
|
|
@ -26,20 +25,6 @@ p = cast[MyPointer](nil)
|
||||||
p = nil.MyPointer
|
p = nil.MyPointer
|
||||||
p = nil
|
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
|
var i: MyInt
|
||||||
i = 1.MyInt
|
i = 1.MyInt
|
||||||
doAssert(compiles(i = nil) == false)
|
doAssert(compiles(i = nil) == false)
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,16 @@ import json
|
||||||
type
|
type
|
||||||
|
|
||||||
foo = object
|
foo = object
|
||||||
thing: string not nil
|
thing: ptr int not nil
|
||||||
|
|
||||||
CTS = ref object
|
CTS = ref object
|
||||||
subs_by_sid: Table[int, foo]
|
subs_by_sid: Table[int, foo]
|
||||||
|
|
||||||
|
|
||||||
proc parse(cts: CTS, jn: JsonNode) =
|
proc parse(cts: CTS, jn: JsonNode) =
|
||||||
|
var y = jn.getInt(4523)
|
||||||
let ces = foo(
|
let ces = foo(
|
||||||
thing: jn.getStr("thing")
|
thing: addr y
|
||||||
)
|
)
|
||||||
|
|
||||||
cts.subs_by_sid[0] = ces
|
cts.subs_by_sid[0] = ces
|
||||||
|
|
@ -63,17 +63,3 @@ proc parse(cts: CTS, jn: JsonNode) =
|
||||||
|
|
||||||
proc p(x: proc(){.closure.} not nil) = discard
|
proc p(x: proc(){.closure.} not nil) = discard
|
||||||
p(proc(){.closure.} = 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]()
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "'y' is provably nil"
|
errormsg: "'y' is provably nil"
|
||||||
line:38
|
line:25
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
@ -10,19 +10,6 @@ type
|
||||||
TObj = object
|
TObj = object
|
||||||
x, y: int
|
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) =
|
proc q(x: pointer not nil) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ discard """
|
||||||
# bug #2355
|
# bug #2355
|
||||||
type
|
type
|
||||||
Foo = object
|
Foo = object
|
||||||
foo: string not nil
|
foo: ref int
|
||||||
bar: string not nil
|
bar: ref int not nil
|
||||||
|
var x: ref int = new(int)
|
||||||
# Create instance without initializaing the `bar` field
|
# Create instance without initializaing the `bar` field
|
||||||
var f = Foo(foo: "foo")
|
var f = Foo(foo: x)
|
||||||
echo f.bar.isNil # true
|
echo f.bar.isNil # true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue