diff options
author | Zahary Karadjov <zahary@gmail.com> | 2020-03-27 20:53:09 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-04-01 19:38:44 +0200 |
commit | 8ae48292ff3e3b38fd4013b1983c860fd0d49f4c (patch) | |
tree | 9a724f79d40c57dc4c4186279bb305d2d4882b70 /compiler/semobjconstr.nim | |
parent | 05a0ec4adb5fc5ce1b92ca8693a688586c5b7371 (diff) | |
download | Nim-8ae48292ff3e3b38fd4013b1983c860fd0d49f4c.tar.gz |
Plug another hole: default(T) forbidden for objects requiring initialization
Diffstat (limited to 'compiler/semobjconstr.nim')
-rw-r--r-- | compiler/semobjconstr.nim | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index 2d226aa33..b9931f527 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -11,6 +11,21 @@ # included from sem.nim +type + ObjConstrContext = object + typ: PType # The constructed type + initExpr: PNode # The init expression (nkObjConstr) + requiresFullInit: bool # A `requiresInit` derived type will + # set this to true while visiting + # parent types. + + InitStatus = enum # This indicates the result of object construction + initUnknown + initFull # All of the fields have been initialized + initPartial # Some of the fields have been initialized + initNone # None of the fields have been initialized + initConflict # Fields from different branches have been initialized + proc mergeInitStatus(existing: var InitStatus, newStatus: InitStatus) = case newStatus of initConflict: @@ -336,6 +351,9 @@ proc semConstructType(c: PContext, initExpr: PNode, constrCtx.requiresFullInit = constrCtx.requiresFullInit or tfRequiresInit in t.flags +proc checkDefaultConstruction(c: PContext, typ: PType, info: TLineInfo) = + discard semConstructType(c, newNodeI(nkObjConstr, info), typ, {}) + proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = var t = semTypeNode(c, n[0], nil) result = newNodeIT(nkObjConstr, n.info, t) |