summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-11-23 02:32:51 +0100
committerAraq <rumpf_a@web.de>2017-11-23 02:32:51 +0100
commit8a601669ef6bedd6ab9f70bd09936d24a6a10ade (patch)
treece3a2f42e48b0cbae29207ec867b3c82d0e4dee6
parent95a5373d07c5761cfffe54dedd08c1649a403247 (diff)
downloadNim-8a601669ef6bedd6ab9f70bd09936d24a6a10ade.tar.gz
fixes #6489
-rw-r--r--compiler/ccgexprs.nim2
-rw-r--r--compiler/seminst.nim2
-rw-r--r--compiler/sempass2.nim2
-rw-r--r--compiler/semtypinst.nim4
-rw-r--r--compiler/types.nim8
-rw-r--r--tests/notnil/tmust_compile.nim8
6 files changed, 20 insertions, 6 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index d7b8ec667..571135fbb 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1693,7 +1693,7 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
 
 proc genConv(p: BProc, e: PNode, d: var TLoc) =
   let destType = e.typ.skipTypes({tyVar, tyGenericInst, tyAlias})
-  if compareTypes(destType, e.sons[1].typ, dcEqIgnoreDistinct):
+  if sameBackendType(destType, e.sons[1].typ):
     expr(p, e.sons[1], d)
   else:
     genSomeCast(p, e, d)
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index dbb73dd4e..acea9330b 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -240,6 +240,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
   resetIdTable(cl.localCache)
   result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
   result.n.sons[0] = originalParams[0].copyTree
+  if result.sons[0] != nil:
+    propagateToOwner(result, result.sons[0])
 
   eraseVoidParams(result)
   skipIntLiteralParams(result)
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index 66c736146..051f215e0 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -525,7 +525,7 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
       # addr(x[]) can't be proven, but addr(x) can:
       if not containsNode(n, {nkDerefExpr, nkHiddenDeref}): return
     elif (n.kind == nkSym and n.sym.kind in routineKinds) or
-         n.kind in procDefs+{nkObjConstr, nkBracket}:
+         n.kind in procDefs+{nkObjConstr, nkBracket, nkClosure}:
       # 'p' is not nil obviously:
       return
     case impliesNotNil(tracked.guards, n)
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 1861b9da3..a42092ae0 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -522,8 +522,8 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
             if r2.kind in {tyPtr, tyRef}:
               r = skipTypes(r2, {tyPtr, tyRef})
           result.sons[i] = r
-          #if result.kind != tyArray or i != 0:
-          #  propagateToOwner(result, r)
+          if result.kind != tyArray or i != 0:
+            propagateToOwner(result, r)
       # bug #4677: Do not instantiate effect lists
       result.n = replaceTypeVarsN(cl, result.n, ord(result.kind==tyProc))
       case result.kind
diff --git a/compiler/types.nim b/compiler/types.nim
index 369d918fd..495a1977d 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -972,7 +972,12 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
      tyArray, tyProc, tyVarargs, tyOrdinal, tyTypeClasses, tyOpt:
     cycleCheck()
     if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
-    result = sameChildrenAux(a, b, c) and sameFlags(a, b)
+    result = sameChildrenAux(a, b, c)
+    if result:
+      if IgnoreTupleFields in c.flags:
+        result = a.flags * {tfVarIsPtr} == b.flags * {tfVarIsPtr}
+      else:
+        result = sameFlags(a, b)
     if result and ExactGcSafety in c.flags:
       result = a.flags * {tfThread} == b.flags * {tfThread}
     if result and a.kind == tyProc:
@@ -992,6 +997,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
 proc sameBackendType*(x, y: PType): bool =
   var c = initSameTypeClosure()
   c.flags.incl IgnoreTupleFields
+  c.cmp = dcEqIgnoreDistinct
   result = sameTypeAux(x, y, c)
 
 proc compareTypes*(x, y: PType,
diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim
index f4ac3724f..117921a57 100644
--- a/tests/notnil/tmust_compile.nim
+++ b/tests/notnil/tmust_compile.nim
@@ -55,4 +55,10 @@ proc parse(cts: CTS, jn: JsonNode) =
     thing: jn.getStr("thing")
   )
 
-  cts.subs_by_sid[0] = ces
\ No newline at end of file
+  cts.subs_by_sid[0] = ces
+
+
+# bug #6489
+
+proc p(x: proc(){.closure.} not nil) = discard
+p(proc(){.closure.} = discard)