diff options
-rwxr-xr-x | compiler/semtypes.nim | 11 | ||||
-rwxr-xr-x | doc/manual.txt | 13 | ||||
-rwxr-xr-x | todo.txt | 2 |
3 files changed, 21 insertions, 5 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 7c1318ada..36b6a449d 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -38,6 +38,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = localError(n.sons[0].info, errInheritanceOnlyWithEnums) counter = lastOrd(base) + 1 rawAddSon(result, base) + let isPure = result.sym != nil and sfPure in result.sym.flags for i in countup(1, sonsLen(n) - 1): case n.sons[i].kind of nkEnumFieldDef: @@ -73,12 +74,12 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = else: illFormedAst(n) e.typ = result e.position = int(counter) - if result.sym != nil and sfExported in result.sym.flags: - incl(e.flags, sfUsed) # BUGFIX - incl(e.flags, sfExported) # BUGFIX - StrTableAdd(c.module.tab, e) # BUGFIX + if result.sym != nil and sfExported in result.sym.flags: + incl(e.flags, sfUsed) + incl(e.flags, sfExported) + if not isPure: StrTableAdd(c.module.tab, e) addSon(result.n, newSymNode(e)) - if sfGenSym notin e.flags: addDeclAt(c, e, c.tab.tos - 1) + if sfGenSym notin e.flags and not isPure: addDeclAt(c, e, c.tab.tos - 1) inc(counter) proc semSet(c: PContext, n: PNode, prev: PType): PType = diff --git a/doc/manual.txt b/doc/manual.txt index e5814b9d6..c8d40c476 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -795,6 +795,19 @@ values to use: As can be seen from the example, it is possible to both specify a field's ordinal value and its string value by using a tuple. It is also possible to only specify one of them. + +An enum can be marked with the ``pure`` pragma so that it's fields are not +added to the current scope, so they always need to be accessed +via ``TMyEnum.value``: + +.. code-block:: nimrod + + type + TMyEnum {.pure.} = enum + valueA, valueB, valueC, valueD + + echo valueA # error: Unknown identifier + echo TMyEnum.valueA # works String type diff --git a/todo.txt b/todo.txt index 3ea45b9b8..c640dd435 100755 --- a/todo.txt +++ b/todo.txt @@ -45,6 +45,8 @@ version 0.9.XX - JS gen: - fix exception handling +- object branch transitions can't work with the current 'reset'; add a 'reset' + with an additional parameter - fix remaining closure bugs: - test evals.nim with closures - what about macros with closures? |