summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-03-18 20:21:36 +0200
committerZahary Karadjov <zahary@gmail.com>2017-04-06 00:46:18 +0300
commitf162214d5d509945a36f70b7ea6ffeb33ad17fe7 (patch)
tree0634798516682ce429ecdccdf2145cabd9647090 /compiler
parent564c0acae20419133f3fadd17be4bae42dd408d9 (diff)
downloadNim-f162214d5d509945a36f70b7ea6ffeb33ad17fe7.tar.gz
object construction: test cases and manual additions
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semexprs.nim18
1 files changed, 8 insertions, 10 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index f80f67160..5a71896ef 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -2146,7 +2146,8 @@ proc semConstrField(c: PContext, flags: TExprFlags,
       return
 
     var initValue = semExprFlagDispatched(c, assignment[1], flags)
-    initValue = fitNode(c, field.typ, initValue, assignment.info)
+    if initValue != nil:
+      initValue = fitNode(c, field.typ, initValue, assignment.info)
     assignment.sons[0] = newSymNode(field)
     assignment.sons[1] = initValue
     assignment.flags.incl nfSem
@@ -2252,9 +2253,8 @@ proc semConstructFields(c: PContext, recNode: PNode,
       if discriminatorVal == nil:
         let fields = fieldsPresentInBranch(selectedBranch)
         localError(initExpr.info,
-          "the discriminator '$1' appearing in the construction of a case " &
-          "object must be a compile-time value in order to prove that it's " &
-          "initialize field(s) $2.",
+          "you must provide a compile-time value for the discriminator '$1' " &
+          "in order to prove that it's safe to initialize $2.",
           [discriminator.sym.name.s, fields])
         mergeInitStatus(result, initNone)
       else:
@@ -2344,17 +2344,15 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   # field (if this is a case object, initialized fields in two different
   # branches will be reported as an error):
   let initResult = semContructType(c, t, n, flags)
-  if initResult == initConflict:
-    localError(n.info,
-      "invalid object construction. " &
-      "fields from conflicting case branches have been initialized.")
-    return
 
   # It's possible that the object was not fully initialized while
   # specifying a .requiresInit. pragma.
   # XXX: Turn this into an error in the next release
   if tfNeedsInit in t.flags and initResult != initFull:
-    message(n.info, warnUser,
+    # XXX: Disable this warning for now, because tfNeedsInit is propagated
+    # too aggressively from fields to object types (and this is not correct
+    # in case objects)
+    when false: message(n.info, warnUser,
       "object type uses the 'requiresInit' pragma, but not all fields " &
       "have been initialized. future versions of Nim will treat this as " &
       "an error")