From d4c2f2509c4ce94929ba9b75c16cf34f982da365 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 16 Apr 2012 17:23:44 +0200 Subject: [PATCH] bugfix: 'error' statement pragma works as expected again --- compiler/pragmas.nim | 18 +++++++++++------- todo.txt | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 7e632d8589..fe8bff34b5 100755 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -26,7 +26,7 @@ const wNoStackFrame, wError, wDiscardable, wNoInit} converterPragmas* = procPragmas methodPragmas* = procPragmas - templatePragmas* = {wImmediate} + templatePragmas* = {wImmediate, wDeprecated, wError} macroPragmas* = {FirstCallConv..LastCallConv, wImmediate, wImportc, wExportc, wNodecl, wMagic, wNosideEffect, wCompilerProc, wDeprecated, wExtern, wImportcpp, wImportobjc, wError, wDiscardable} @@ -560,10 +560,14 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = of wHint: Message(it.info, hintUser, expectStrLit(c, it)) of wWarning: Message(it.info, warnUser, expectStrLit(c, it)) of wError: - if sym != nil: + if sym != nil and sym.isRoutine: + # This is subtle but correct: the error *statement* is only + # allowed for top level statements. Seems to be easier than + # distinguishing properly between + # ``proc p() {.error}`` and ``proc p() = {.error: "msg".}`` noVal(it) incl(sym.flags, sfError) - else: + else: LocalError(it.info, errUser, expectStrLit(c, it)) of wFatal: Fatal(it.info, errUser, expectStrLit(c, it)) of wDefine: processDefine(c, it) @@ -609,12 +613,12 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = else: invalidPragma(it) else: invalidPragma(it) else: processNote(c, it) - if (sym != nil) and (sym.kind != skModule): - if (lfExportLib in sym.loc.flags) and not (sfExportc in sym.flags): + if sym != nil and sym.kind != skModule: + if lfExportLib in sym.loc.flags and sfExportc notin sym.flags: LocalError(n.info, errDynlibRequiresExportc) var lib = POptionEntry(c.optionstack.tail).dynlib - if ({lfDynamicLib, lfHeader} * sym.loc.flags == {}) and - (sfImportc in sym.flags) and (lib != nil): + if {lfDynamicLib, lfHeader} * sym.loc.flags == {} and + sfImportc in sym.flags and lib != nil: incl(sym.loc.flags, lfDynamicLib) addToLib(lib, sym) if sym.loc.r == nil: sym.loc.r = toRope(sym.name.s) diff --git a/todo.txt b/todo.txt index 7e037605c0..0a17d94e87 100755 --- a/todo.txt +++ b/todo.txt @@ -44,7 +44,6 @@ Bugs - bug: stress testing basic method example (eval example) without ``-d:release`` leaks memory? - bug: object {.pure, final.} does not work again! -- bug: {.error: "msg".} produces invalid pragma message - bug: pragma statements in combination with symbol files are evaluated twice but this can lead to compilation errors