summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2020-04-01 03:33:32 +0300
committerAndreas Rumpf <rumpf_a@web.de>2020-04-01 19:38:44 +0200
commitbe95f8fdfac9ceb559f77b55630ca9e285fa9a2d (patch)
treec4819894e2f0fdf8a720795880ece26c8e5e5795 /compiler
parentce9a4ed124d798d0287a62e4700a32f1d15878c9 (diff)
downloadNim-be95f8fdfac9ceb559f77b55630ca9e285fa9a2d.tar.gz
Turn some of the errors back into warnings
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lineinfos.nim6
-rw-r--r--compiler/semexprs.nim14
-rw-r--r--compiler/semmagic.nim17
-rw-r--r--compiler/semobjconstr.nim5
-rw-r--r--compiler/sempass2.nim6
5 files changed, 30 insertions, 18 deletions
diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim
index 585a95c80..658863676 100644
--- a/compiler/lineinfos.nim
+++ b/compiler/lineinfos.nim
@@ -37,6 +37,8 @@ type
     warnUnusedImportX,
     warnInheritFromException,
     warnEachIdentIsTuple,
+    warnUnsafeSetLen,
+    warnUnsafeDefault,
     warnProveInit, warnProveField, warnProveIndex,
     warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2,
     warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
@@ -87,6 +89,9 @@ const
     warnUnusedImportX: "imported and not used: '$1'",
     warnInheritFromException: "inherit from a more precise exception type like ValueError, IOError or OSError",
     warnEachIdentIsTuple: "each identifier is a tuple",
+    warnUnsafeSetLen: "setLen can potentially expand the sequence, " &
+                      "but the element type '$1' doesn't have a valid default value",
+    warnUnsafeDefault: "The '$1' type doesn't have a valid default value",
     warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future.",
     warnProveField: "cannot prove that field '$1' is accessible",
     warnProveIndex: "cannot prove index '$1' is valid",
@@ -146,6 +151,7 @@ const
     "TypelessParam", "UseBase", "WriteToForeignHeap",
     "UnsafeCode", "UnusedImport", "InheritFromException",
     "EachIdentIsTuple",
+    "UnsafeSetLen", "UnsafeDefault",
     "ProveInit", "ProveField", "ProveIndex",
     "IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
     "GcMem", "Destructor", "LockLevel", "ResultShadowed",
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 56de00d56..5f82eb1e7 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -2267,20 +2267,6 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
   of mSizeOf:
     markUsed(c, n.info, s)
     result = semSizeof(c, setMs(n, s))
-  of mSetLengthSeq:
-    result = semDirectOp(c, n, flags)
-    let seqType = result[1].typ.skipTypes({tyPtr, tyRef, # in case we had auto-dereferencing
-                                           tyVar, tyGenericInst, tyOwned, tySink,
-                                           tyAlias, tyUserTypeClassInst})
-    if seqType.kind == tySequence and seqType.base.requiresInit:
-      localError(c.config, n.info, "setLen can potentially expand the sequence, " &
-                                   "but the element type $1 doesn't have a default value.",
-                                   [typeToString(seqType.base)])
-  of mDefault:
-    result = semDirectOp(c, n, flags)
-    c.config.internalAssert result[1].typ.kind == tyTypeDesc
-    if result[1].typ.base.requiresInit:
-      localError(c.config, n.info, "not nil types don't have a default value")
   else:
     result = semDirectOp(c, n, flags)
 
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 8c07d7d18..783846650 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -530,4 +530,19 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
     result = semQuantifier(c, n)
   of mOld:
     result = semOld(c, n)
-  else: result = n
+  of mSetLengthSeq:
+    result = n
+    let seqType = result[1].typ.skipTypes({tyPtr, tyRef, # in case we had auto-dereferencing
+                                           tyVar, tyGenericInst, tyOwned, tySink,
+                                           tyAlias, tyUserTypeClassInst})
+    if seqType.kind == tySequence and seqType.base.requiresInit:
+      message(c.config, n.info, warnUnsafeSetLen, typeToString(seqType.base))
+  of mDefault:
+    result = n
+    c.config.internalAssert result[1].typ.kind == tyTypeDesc
+    let constructed = result[1].typ.base
+    if constructed.requiresInit:
+      message(c.config, n.info, warnUnsafeDefault, typeToString(constructed))
+  else:
+    result = n
+
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim
index eb0589601..eeec42900 100644
--- a/compiler/semobjconstr.nim
+++ b/compiler/semobjconstr.nim
@@ -336,6 +336,11 @@ proc semConstructTypeAux(c: PContext,
     let base = t[0]
     if base == nil: break
     t = skipTypes(base, skipPtrs)
+    if t.kind == tyGenericParam:
+      # XXX: This is not supposed to happen, but apparently
+      # there are some issues in semtypinst. Luckily, it
+      # seems to affect only `computeRequiresInit`.
+      return
     constrCtx.needsFullInit = constrCtx.needsFullInit or
                               tfNeedsFullInit in t.flags
 
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index 79d969fbb..a4e1dcf00 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -254,7 +254,7 @@ proc useVar(a: PEffects, n: PNode) =
       a.init.add s.id
     elif s.id notin a.init:
       if s.typ.requiresInit:
-        localError(a.config, n.info, errProveInit, s.name.s)
+        message(a.config, n.info, warnProveInit, s.name.s)
       else:
         message(a.config, n.info, warnUninit, s.name.s)
       # prevent superfluous warnings about the same variable:
@@ -844,7 +844,7 @@ proc track(tracked: PEffects, n: PNode) =
           # var s: seq[notnil];  newSeq(s, 0)  is a special case!
           discard
         else:
-          localError(tracked.config, arg.info, errProveInit, $arg)
+          message(tracked.config, arg.info, warnProveInit, $arg)
 
       # check required for 'nim check':
       if n[1].typ.len > 0:
@@ -1209,7 +1209,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
      s.kind in {skProc, skFunc, skConverter, skMethod}:
     var res = s.ast[resultPos].sym # get result symbol
     if res.id notin t.init:
-      localError(g.config, body.info, errProveInit, "result")
+      message(g.config, body.info, warnProveInit, "result")
   let p = s.ast[pragmasPos]
   let raisesSpec = effectSpec(p, wRaises)
   if not isNil(raisesSpec):