diff options
-rw-r--r-- | compiler/parser.nim | 8 | ||||
-rw-r--r-- | tests/closure/tdonotation.nim | 14 |
2 files changed, 10 insertions, 12 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index e9dff25ac..561200bcc 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1172,7 +1172,7 @@ proc parseMacroColon(p: var TParser, x: PNode): PNode = result = makeCall(result) getTok(p) skipComment(p, result) - let stmtList = newNodeP(nkStmtList, p) + var stmtList = newNodeP(nkStmtList, p) if p.tok.tokType notin {tkOf, tkElif, tkElse, tkExcept}: let body = parseStmt(p) stmtList.add body @@ -1202,9 +1202,9 @@ proc parseMacroColon(p: var TParser, x: PNode): PNode = if b.kind == nkElse: break if stmtList.len == 1 and stmtList[0].kind == nkStmtList: # to keep backwards compatibility (see tests/vm/tstringnil) - result.add stmtList[0] - else: - result.add stmtList + stmtList = stmtList[0] + result.add newProcNode(nkDo, stmtList.info, stmtList, + params = emptyNode, pragmas = emptyNode) proc parseExprStmt(p: var TParser): PNode = #| exprStmt = simpleExpr diff --git a/tests/closure/tdonotation.nim b/tests/closure/tdonotation.nim index 795b18f86..5acb17da2 100644 --- a/tests/closure/tdonotation.nim +++ b/tests/closure/tdonotation.nim @@ -1,8 +1,10 @@ discard """ output: ''' click at 10,20 +lost focus 1 lost focus 2 registered handler for UserEvent 1 +registered handler for UserEvent 2 registered handler for UserEvent 3''' """ @@ -27,10 +29,8 @@ var b = Button() b.onClick do (e: Event): echo "click at ", e.x, ",", e.y -when false: - # this syntax doesn't work yet - b.onFocusLost: - echo "lost focus 1" +b.onFocusLost: + echo "lost focus 1" b.onFocusLost do: echo "lost focus 2" @@ -38,10 +38,8 @@ b.onFocusLost do: b.onUserEvent("UserEvent 1") do: discard -when false: - # this syntax doesn't work yet - b.onUserEvent("UserEvent 2"): - discard +b.onUserEvent("UserEvent 2"): + discard b.onUserEvent("UserEvent 3", () => echo "event 2") |