diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-10-29 07:54:39 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-10-29 07:54:39 +0100 |
commit | c17f6c7837d9fc2268543e34c03f95e50229650d (patch) | |
tree | b9d5684711c314ebf8b56b3f9b1b218ce39cdae5 /compiler | |
parent | 7889692523c5738c901609024ebabf91b44fa719 (diff) | |
download | Nim-c17f6c7837d9fc2268543e34c03f95e50229650d.tar.gz |
new feature: package level objects
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgtypes.nim | 5 | ||||
-rw-r--r-- | compiler/semstmts.nim | 15 |
2 files changed, 11 insertions, 9 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 76d0c0158..c5fc67fb0 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -981,7 +981,10 @@ proc genTypeInfoAux(m: BModule, typ, origType: PType, name: Rope; if sonsLen(typ) > 0 and typ.lastSon != nil: var x = typ.lastSon if typ.kind == tyObject: x = x.skipTypes(skipPtrs) - base = genTypeInfo(m, x, info) + if typ.kind == tyPtr and x.kind == tyObject and incompleteType(x): + base = rope("0") + else: + base = genTypeInfo(m, x, info) else: base = rope("0") genTypeInfoAuxBase(m, typ, origType, name, base, info) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index e2ee9ac67..8ec93cacd 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -796,12 +796,6 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) = else: localError(name.info, typsym.name.s & " is not a type that can be forwarded") s = typsym - when false: - s = qualifiedLookUp(c, name, {checkUndeclared, checkModule}) - if s.kind != skType or - s.typ.skipTypes(abstractPtrs).kind != tyObject or - tfPartial notin s.typ.skipTypes(abstractPtrs).flags: - localError(name.info, "only .partial objects can be extended") else: s = semIdentDef(c, name, skType) s.typ = newTypeS(tyForward, c) @@ -812,11 +806,16 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) = # check if the symbol already exists: let pkg = c.module.owner if not isTopLevel(c) or pkg.isNil: - localError(name.info, "only top level types in a package can be 'forward'") + localError(name.info, "only top level types in a package can be 'package'") else: let typsym = pkg.tab.strTableGet(s.name) if typsym != nil: - typeCompleted(typsym) + if sfForward notin typsym.flags or sfNoForward notin typsym.flags: + typeCompleted(typsym) + typsym.info = s.info + else: + localError(name.info, "cannot complete type '" & s.name.s & "' twice; " & + "previous type completion was here: " & $typsym.info) s = typsym # add it here, so that recursive types are possible: if sfGenSym notin s.flags: addInterfaceDecl(c, s) |