summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-08-13 17:27:44 +0200
committerAraq <rumpf_a@web.de>2018-08-13 17:27:44 +0200
commit420ed0596b8114c67275c4702fa3524ebd76e5eb (patch)
treef381eaedb04743a43faa1ded7e5d77ac5952ab3e
parentd60bb1b289c7914443a20b78bfb6c69f05184937 (diff)
downloadNim-420ed0596b8114c67275c4702fa3524ebd76e5eb.tar.gz
fixes more nil handling regressions
-rw-r--r--compiler/ast.nim4
-rw-r--r--compiler/patterns.nim8
-rw-r--r--lib/deprecated/pure/actors.nim3
-rw-r--r--lib/pure/httpclient.nim14
-rw-r--r--tests/casestmt/tcasestm.nim18
-rw-r--r--tests/exception/tdont_overwrite_typename.nim4
-rw-r--r--tests/notnil/tnotnil.nim12
-rw-r--r--tests/pragmas/custom_pragma.nim2
-rw-r--r--tests/system/tostring.nim10
-rw-r--r--tests/threads/tactors.nim4
-rw-r--r--tests/tuples/tuple_with_nil.nim24
-rw-r--r--tests/tuples/tuple_with_seq.nim4
-rw-r--r--tests/types/temptyseqs.nim2
13 files changed, 49 insertions, 60 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 7d8d098e3..e294eccc2 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -971,8 +971,8 @@ const
     tyFloat..tyFloat128, tyUInt..tyUInt64}
   ConstantDataTypes*: TTypeKinds = {tyArray, tySet,
                                     tyTuple, tySequence}
-  NilableTypes*: TTypeKinds = {tyPointer, tyCString, tyRef, tyPtr, tySequence,
-    tyProc, tyString, tyError}
+  NilableTypes*: TTypeKinds = {tyPointer, tyCString, tyRef, tyPtr,
+    tyProc, tyError}
   ExportableSymKinds* = {skVar, skConst, skProc, skFunc, skMethod, skType,
     skIterator,
     skMacro, skTemplate, skConverter, skEnumField, skLet, skStub, skAlias}
diff --git a/compiler/patterns.nim b/compiler/patterns.nim
index aa06342f9..ebb3a7c1d 100644
--- a/compiler/patterns.nim
+++ b/compiler/patterns.nim
@@ -21,14 +21,17 @@ type
     formals: int
     c: PContext
     subMatch: bool       # subnode matches are special
+    mappingIsFull: bool
   PPatternContext = var TPatternContext
 
 proc getLazy(c: PPatternContext, sym: PSym): PNode =
-  if not isNil(c.mapping):
+  if c.mappingIsFull:
     result = c.mapping[sym.position]
 
 proc putLazy(c: PPatternContext, sym: PSym, n: PNode) =
-  if isNil(c.mapping): newSeq(c.mapping, c.formals)
+  if not c.mappingIsFull:
+    newSeq(c.mapping, c.formals)
+    c.mappingIsFull = true
   c.mapping[sym.position] = n
 
 proc matches(c: PPatternContext, p, n: PNode): bool
@@ -211,6 +214,7 @@ proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
         # we need to undo any bindings:
         when defined(nimNoNilSeqs):
           c.mapping = @[]
+          c.mappingIsFull = false
         else:
           if not isNil(c.mapping): c.mapping = nil
         return false
diff --git a/lib/deprecated/pure/actors.nim b/lib/deprecated/pure/actors.nim
index 17321cc0e..451668825 100644
--- a/lib/deprecated/pure/actors.nim
+++ b/lib/deprecated/pure/actors.nim
@@ -43,7 +43,6 @@ type
     t: Thread[ptr Actor[In, Out]]
 
   PActor*[In, Out] = ptr Actor[In, Out] ## an actor
-{.deprecated: [TTask: Task, TActor: Actor].}
 
 proc spawn*[In, Out](action: proc(
     self: PActor[In, Out]){.thread.}): PActor[In, Out] =
@@ -168,7 +167,7 @@ proc terminate*[In, Out](a: var ActorPool[In, Out]) =
   for i in 0..<a.actors.len: join(a.actors[i])
   when Out isnot void:
     close(a.outputs)
-  a.actors = nil
+  a.actors = @[]
 
 proc join*[In, Out](a: var ActorPool[In, Out]) =
   ## short-cut for `sync` and then `terminate`.
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index a98779db3..0192e71e7 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -378,23 +378,23 @@ proc newMultipartData*: MultipartData =
   ## Constructs a new ``MultipartData`` object.
   MultipartData(content: @[])
 
-proc add*(p: var MultipartData, name, content: string, filename: string = nil,
-          contentType: string = nil) =
+proc add*(p: var MultipartData, name, content: string, filename: string = "",
+          contentType: string = "") =
   ## Add a value to the multipart data. Raises a `ValueError` exception if
   ## `name`, `filename` or `contentType` contain newline characters.
 
   if {'\c','\L'} in name:
     raise newException(ValueError, "name contains a newline character")
-  if filename != nil and {'\c','\L'} in filename:
+  if {'\c','\L'} in filename:
     raise newException(ValueError, "filename contains a newline character")
-  if contentType != nil and {'\c','\L'} in contentType:
+  if {'\c','\L'} in contentType:
     raise newException(ValueError, "contentType contains a newline character")
 
   var str = "Content-Disposition: form-data; name=\"" & name & "\""
-  if filename != nil:
+  if filename.len > 0:
     str.add("; filename=\"" & filename & "\"")
   str.add("\c\L")
-  if contentType != nil:
+  if contentType.len > 0:
     str.add("Content-Type: " & contentType & "\c\L")
   str.add("\c\L" & content & "\c\L")
 
@@ -434,7 +434,7 @@ proc addFiles*(p: var MultipartData, xs: openarray[tuple[name, file: string]]):
     var contentType: string
     let (_, fName, ext) = splitFile(file)
     if ext.len > 0:
-      contentType = m.getMimetype(ext[1..ext.high], nil)
+      contentType = m.getMimetype(ext[1..ext.high], "")
     p.add(name, readFile(file), fName & ext, contentType)
   result = p
 
diff --git a/tests/casestmt/tcasestm.nim b/tests/casestmt/tcasestm.nim
index 4d32d023f..ff912ffab 100644
--- a/tests/casestmt/tcasestm.nim
+++ b/tests/casestmt/tcasestm.nim
@@ -41,16 +41,16 @@ let str2 = "NN"
 let a = case str1:
   of "Y": true
   of "N": false
-  else: 
+  else:
     echo "no good"
     quit("quiting")
 
-proc toBool(s: string): bool = 
+proc toBool(s: string): bool =
   case s:
-    of nil, "": raise newException(ValueError, "Invalid boolean")
-    elif s[0] == 'Y': true
-    elif s[0] == 'N': false
-    else: "error".quit(2)
+  of "": raise newException(ValueError, "Invalid boolean")
+  elif s[0] == 'Y': true
+  elif s[0] == 'N': false
+  else: "error".quit(2)
 
 
 let b = "NN".toBool()
@@ -66,7 +66,7 @@ static:
 var bb: bool
 doassert(not compiles(
   bb = case str2:
-    of nil, "": raise newException(ValueError, "Invalid boolean")
+    of "": raise newException(ValueError, "Invalid boolean")
     elif str.startsWith("Y"): true
     elif str.startsWith("N"): false
 ))
@@ -94,7 +94,7 @@ doassert(not compiles(
   bb = case str2:
     of "Y":
       raise newException(ValueError, "Invalid Y")
-      true    
+      true
     else: raise newException(ValueError, "Invalid")
 ))
 
@@ -103,6 +103,6 @@ doassert(not compiles(
   bb = case str2:
     of "Y":
       "invalid Y".quit(3)
-      true    
+      true
     else: raise newException(ValueError, "Invalid")
 ))
\ No newline at end of file
diff --git a/tests/exception/tdont_overwrite_typename.nim b/tests/exception/tdont_overwrite_typename.nim
index 6e3ff816f..d6dca0990 100644
--- a/tests/exception/tdont_overwrite_typename.nim
+++ b/tests/exception/tdont_overwrite_typename.nim
@@ -7,10 +7,10 @@ Check passed'''
 # bug #5628
 
 proc checkException(ex: ref Exception) =
-  doAssert(ex.name == "ValueError")
+  doAssert(ex.name == cstring"ValueError")
   doAssert(ex.msg == "SecondException")
   doAssert(ex.parent != nil)
-  doAssert(ex.parent.name == "KeyError")
+  doAssert(ex.parent.name == cstring"KeyError")
   doAssert(ex.parent.msg == "FirstException")
   echo "Check passed"
 
diff --git a/tests/notnil/tnotnil.nim b/tests/notnil/tnotnil.nim
index e392b155c..aff3f8959 100644
--- a/tests/notnil/tnotnil.nim
+++ b/tests/notnil/tnotnil.nim
@@ -1,5 +1,5 @@
 discard """
-  line: 22
+  line: 13
   errormsg: "type mismatch"
 """
 {.experimental: "notnil".}
@@ -8,16 +8,6 @@ type
   TObj = object
     x: int
 
-  MyString = string not nil
-
-#var x: PObj = nil
-
-proc p(x: string not nil): int =
-  result = 45
-
-proc q(x: MyString) = discard
 proc q2(x: string) = discard
 
 q2(nil)
-q(nil)
-
diff --git a/tests/pragmas/custom_pragma.nim b/tests/pragmas/custom_pragma.nim
index 9e8f51deb..d2fc969d0 100644
--- a/tests/pragmas/custom_pragma.nim
+++ b/tests/pragmas/custom_pragma.nim
@@ -2,4 +2,4 @@
 
 template serializationKey*(s: string) {.pragma.}
 template defaultValue*(V: typed) {.pragma.}
-template alternativeKey*(s: string = nil, V: typed) {.pragma.}
\ No newline at end of file
+template alternativeKey*(s: string = "", V: typed) {.pragma.}
diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim
index 9a6b83f95..99299f203 100644
--- a/tests/system/tostring.nim
+++ b/tests/system/tostring.nim
@@ -26,8 +26,8 @@ doAssert "nan" == $(0.0/0.0)
 var x: seq[string]
 doAssert "nil" == $(x)
 
-var y: string = nil
-doAssert nil == $(y)
+var y: string
+doAssert "" == $(y)
 
 type
   Foo = object
@@ -54,7 +54,7 @@ doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '
 doAssert $cstring(unsafeAddr arr) == "Hello World!"
 
 proc takes(c: cstring) =
-  doAssert c == ""
+  doAssert c == cstring""
 
 proc testm() =
   var x: string
@@ -90,12 +90,8 @@ proc stringCompare() =
 
   doAssert e == ""
   doAssert "" == e
-  doAssert nil == e
-  doAssert e == nil
   doAssert f == g
   doAssert "" == ""
-  doAssert "" == nil
-  doAssert nil == ""
 
   g.setLen(10)
   doAssert g == "\0\0\0\0\0\0\0\0\0\0"
diff --git a/tests/threads/tactors.nim b/tests/threads/tactors.nim
index 45a03ebb7..ea052b9bd 100644
--- a/tests/threads/tactors.nim
+++ b/tests/threads/tactors.nim
@@ -5,9 +5,9 @@ discard """
 import actors
 
 var
-  pool: TActorPool[int, void]
+  pool: ActorPool[int, void]
 createActorPool(pool)
-for i in 0 .. < 300:
+for i in 0 ..< 300:
   pool.spawn(i, proc (x: int) {.thread.} = echo x)
 pool.join()
 
diff --git a/tests/tuples/tuple_with_nil.nim b/tests/tuples/tuple_with_nil.nim
index ec48337bd..e09c53407 100644
--- a/tests/tuples/tuple_with_nil.nim
+++ b/tests/tuples/tuple_with_nil.nim
@@ -73,7 +73,7 @@ type
 
 const
   DefaultPrec = 6 ## Default precision for floating point numbers.
-  DefaultFmt: Format = (ftDefault, -1, -1, nil, faDefault, fsMinus, false, false, false, nil)
+  DefaultFmt: Format = (ftDefault, -1, -1, "", faDefault, fsMinus, false, false, false, "")
     ## Default format corresponding to the empty format string, i.e.
     ##   `x.format("") == x.format(DefaultFmt)`.
   round_nums = [0.5, 0.05, 0.005, 0.0005, 0.00005, 0.000005, 0.0000005, 0.00000005]
@@ -124,7 +124,7 @@ proc parse(fmt: string): Format {.nosideeffect.} =
   if fmt.rawmatch(p, 0, caps) < 0:
     raise newException(FormatError, "Invalid format string")
 
-  result.fill = fmt.get(caps, 0, nil)
+  result.fill = fmt.get(caps, 0, "")
 
   case fmt.get(caps, 1, 0.char)
   of '<': result.align = faLeft
@@ -144,7 +144,7 @@ proc parse(fmt: string): Format {.nosideeffect.} =
   result.width = fmt.get(caps, 4, -1)
 
   if caps.has(4) and fmt[caps.bounds(4).first] == '0':
-    if result.fill != nil:
+    if result.fill != "":
       raise newException(FormatError, "Leading 0 in with not allowed with explicit fill character")
     if result.align != faDefault:
       raise newException(FormatError, "Leading 0 in with not allowed with explicit alignment")
@@ -171,7 +171,7 @@ proc parse(fmt: string): Format {.nosideeffect.} =
   of '%': result.typ = ftPercent
   else: result.typ = ftDefault
 
-  result.arysep = fmt.get(caps, 8, nil, 1)
+  result.arysep = fmt.get(caps, 8, "", 1)
 
 proc getalign(fmt: Format; defalign: FmtAlign; slen: int) : tuple[left, right:int] {.nosideeffect.} =
   ## Returns the number of left and right padding characters for a
@@ -218,7 +218,7 @@ proc writefill(o: var Writer; fmt: Format; n: int; signum: int = 0) =
     elif fmt.sign == fsPlus: write(o, '+')
     elif fmt.sign == fsSpace: write(o, ' ')
 
-  if fmt.fill == nil:
+  if fmt.fill.len == 0:
     for i in 1..n: write(o, ' ')
   else:
     for i in 1..n:
@@ -626,19 +626,19 @@ proc splitfmt(s: string): seq[Part] {.compiletime, nosideeffect.} =
       else:
         lvl.dec
     let clpos = pos
-    var fmtpart = Part(kind: pkFmt, arg: -1, fmt: s.substr(oppos+1, clpos-1), field: nil, index: int.high, nested: nested)
+    var fmtpart = Part(kind: pkFmt, arg: -1, fmt: s.substr(oppos+1, clpos-1), field: "", index: int.high, nested: nested)
     if fmtpart.fmt.len > 0:
       var m: array[0..3, string]
       if not fmtpart.fmt.match(subpeg, m):
         error("invalid format string")
 
-      if m[1] != nil and m[1].len > 0:
+      if m[1].len > 0:
         fmtpart.field = m[1].substr(1)
-      if m[2] != nil and m[2].len > 0:
+      if m[2].len > 0:
         discard parseInt(m[2].substr(1, m[2].len-2), fmtpart.index)
 
       if m[0].len > 0: discard parseInt(m[0], fmtpart.arg)
-      if m[3] == nil or m[3].len == 0:
+      if m[3].len == 0:
         fmtpart.fmt = ""
       elif m[3][0] == ':':
         fmtpart.fmt = m[3].substr(1)
@@ -650,7 +650,7 @@ proc splitfmt(s: string): seq[Part] {.compiletime, nosideeffect.} =
 proc literal(s: string): NimNode {.compiletime, nosideeffect.} =
   ## Return the nim literal of string `s`. This handles the case if
   ## `s` is nil.
-  result = if s == nil: newNilLit() else: newLit(s)
+  result = newLit(s)
 
 proc literal(b: bool): NimNode {.compiletime, nosideeffect.} =
   ## Return the nim literal of boolean `b`. This is either `true`
@@ -713,7 +713,7 @@ proc generatefmt(fmtstr: string;
           args[arg].cnt = args[arg].cnt + 1
           arg.inc
         # possible field access
-        if part.field != nil and part.field.len > 0:
+        if part.field.len > 0:
           argexpr = newDotExpr(argexpr, part.field.ident)
         # possible array access
         if part.index < int.high:
@@ -724,7 +724,7 @@ proc generatefmt(fmtstr: string;
           # nested format string. Compute the format string by
           # concatenating the parts of the substring.
           for e in generatefmt(part.fmt, args, arg):
-            var newexpr = if part.fmt == nil: e.val else: newCall(bindsym"format", e.val, e.fmt)
+            var newexpr = if part.fmt.len == 0: e.val else: newCall(bindsym"format", e.val, e.fmt)
             if fmtexpr != nil and fmtexpr.kind != nnkNilLit:
               fmtexpr = infix(fmtexpr, "&", newexpr)
             else:
diff --git a/tests/tuples/tuple_with_seq.nim b/tests/tuples/tuple_with_seq.nim
index 39edb500f..00b07dd2c 100644
--- a/tests/tuples/tuple_with_seq.nim
+++ b/tests/tuples/tuple_with_seq.nim
@@ -3,8 +3,8 @@ discard """
 @[1, 2, 3]'''
 """
 
-template foo(s: string = nil) =
-  if isNil(s):
+template foo(s: string = "") =
+  if s.len == 0:
     echo "it's nil"
   else:
     echo s
diff --git a/tests/types/temptyseqs.nim b/tests/types/temptyseqs.nim
index 834f63729..28c3b87b8 100644
--- a/tests/types/temptyseqs.nim
+++ b/tests/types/temptyseqs.nim
@@ -22,7 +22,7 @@ when true:
   import os
 
   type
-    In_out = tuple[src, dest, options: string]
+    In_out = tuple[src, dest: string, options: ref int]
 
   let
     nil_var: In_out = ("hey"/"there", "something", nil)