diff options
Diffstat (limited to 'tests/notnil')
-rw-r--r-- | tests/notnil/tmust_compile.nim | 10 | ||||
-rw-r--r-- | tests/notnil/tnotnil4.nim | 5 | ||||
-rw-r--r-- | tests/notnil/tnotnil5.nim | 28 | ||||
-rw-r--r-- | tests/notnil/tnotnil_in_objconstr.nim | 10 | ||||
-rw-r--r-- | tests/notnil/tparse.nim | 18 |
5 files changed, 66 insertions, 5 deletions
diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim index d09dda057..3a013e9ed 100644 --- a/tests/notnil/tmust_compile.nim +++ b/tests/notnil/tmust_compile.nim @@ -63,3 +63,13 @@ proc parse(cts: CTS, jn: JsonNode) = proc p(x: proc(){.closure.} not nil) = discard p(proc(){.closure.} = discard) + +# bug #6490 + +proc p2(a: proc()) = + if a.isNil: + raise newException(ValueError, "a is nil") + else: + let b: proc() not nil = a + +p2(writeStackTrace) diff --git a/tests/notnil/tnotnil4.nim b/tests/notnil/tnotnil4.nim index 4fd169827..c5178f71b 100644 --- a/tests/notnil/tnotnil4.nim +++ b/tests/notnil/tnotnil4.nim @@ -10,8 +10,9 @@ proc check(a: TObj not nil) = proc doit() = var x : array[0..1, TObj] - if x[0] != nil: - check(x[0]) + let y = x[0] + if y != nil: + check(y) doit() diff --git a/tests/notnil/tnotnil5.nim b/tests/notnil/tnotnil5.nim new file mode 100644 index 000000000..2dcb7f7c3 --- /dev/null +++ b/tests/notnil/tnotnil5.nim @@ -0,0 +1,28 @@ +discard """ + matrix: "--threads:on" +""" + +{.experimental: "parallel".} +{.experimental: "notnil".} +import threadpool + +type + AO = object + x: int + + A = ref AO not nil + +proc process(a: A): A = + return A(x: a.x+1) + +proc processMany(ayys: openArray[A]): seq[A] = + var newAs: seq[FlowVar[A]] + + parallel: + for a in ayys: + newAs.add(spawn process(a)) + for newAflow in newAs: + let newA = ^newAflow + if isNil(newA): + return @[] + result.add(newA) diff --git a/tests/notnil/tnotnil_in_objconstr.nim b/tests/notnil/tnotnil_in_objconstr.nim index fb8ac8d6f..471150f44 100644 --- a/tests/notnil/tnotnil_in_objconstr.nim +++ b/tests/notnil/tnotnil_in_objconstr.nim @@ -1,13 +1,17 @@ discard """ - errormsg: "fields not initialized: bar" - line: "13" + errormsg: "The Foo type requires the following fields to be initialized: bar, baz" + line: "17" """ {.experimental: "notnil".} # bug #2355 type - Foo = object + Base = object of RootObj + baz: ref int not nil + + Foo = object of Base foo: ref int bar: ref int not nil + var x: ref int = new(int) # Create instance without initializing the `bar` field var f = Foo(foo: x) diff --git a/tests/notnil/tparse.nim b/tests/notnil/tparse.nim new file mode 100644 index 000000000..5c938ff04 --- /dev/null +++ b/tests/notnil/tparse.nim @@ -0,0 +1,18 @@ +# issue #16324 + +{.push experimental: "notnil".} + +block: + type Foo = ref object + value: int + + proc newFoo1(): Foo not nil = # This compiles + return Foo(value: 1) + + proc newFoo2(): Foo not nil {.inline.} = # This does not + return Foo(value: 1) + + doAssert newFoo1().value == 1 + doAssert newFoo2().value == 1 + +{.pop.} |