From ada0f14711d3eff140f05f8a845cff5d489a71fd Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 8 Feb 2015 14:15:02 +0100 Subject: [PATCH] fixes #2073 --- compiler/semstmts.nim | 4 ++-- lib/system.nim | 2 +- tests/closure/ttimeinfo.nim | 15 +++++++++++++++ web/news.txt | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/closure/ttimeinfo.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index b4790e4212..6e5b272de5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -825,9 +825,9 @@ proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode = if gp.len == 0 or (gp.len == 1 and tfRetType in gp[0].typ.flags): pushProcCon(c, s) addResult(c, s.typ.sons[0], n.info, skProc) + addResultNode(c, n) let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) n.sons[bodyPos] = transformBody(c.module, semBody, s) - addResultNode(c, n) popProcCon(c) elif efOperand notin flags: localError(n.info, errGenericLambdaNotAllowed) @@ -860,9 +860,9 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode = addParams(c, n.typ.n, skProc) pushProcCon(c, s) addResult(c, n.typ.sons[0], n.info, skProc) + addResultNode(c, n) let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) n.sons[bodyPos] = transformBody(c.module, semBody, n.sons[namePos].sym) - addResultNode(c, n) popProcCon(c) popOwner() closeScope(c) diff --git a/lib/system.nim b/lib/system.nim index 19836b68c5..ef70a26728 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3161,7 +3161,7 @@ when hostOS != "standalone": x[j+i] = item[j] inc(j) -proc compiles*(x): bool {.magic: "Compiles", noSideEffect.} = +proc compiles*(x: expr): bool {.magic: "Compiles", noSideEffect.} = ## Special compile-time procedure that checks whether `x` can be compiled ## without any semantic error. ## This can be used to check whether a type supports some operation: diff --git a/tests/closure/ttimeinfo.nim b/tests/closure/ttimeinfo.nim new file mode 100644 index 0000000000..3138ae72e7 --- /dev/null +++ b/tests/closure/ttimeinfo.nim @@ -0,0 +1,15 @@ +# bug #2073 + +import sequtils +import times + +# 1 +proc f(n: int): TimeInfo = + TimeInfo(year: n, month: mJan, monthday: 1) + +echo toSeq(2000 || 2015).map(f) + +# 2 +echo toSeq(2000 || 2015).map(proc (n: int): TimeInfo = + TimeInfo(year: n, month: mJan, monthday: 1) +) diff --git a/web/news.txt b/web/news.txt index f765479a29..4c97c5f9b0 100644 --- a/web/news.txt +++ b/web/news.txt @@ -21,7 +21,8 @@ News should be used instead. - ``nim idetools`` has been replaced by a separate tool `nimsuggest`_. - *arrow like* operators are not right associative anymore. - + - Typeless parameters are now only allowed in templates and macros. The old + way turned out to be too error-prone. Language Additions ------------------