From 64aec6eb85b79f21c9da1d9d0c475942514180c5 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 4 Aug 2020 12:45:15 +0200 Subject: [PATCH] fixes a collect() bug reported on the forum (#15156) [backport:1.2] --- compiler/semstmts.nim | 2 +- compiler/varpartitions.nim | 2 +- lib/pure/sugar.nim | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 68f0cee644..1315e8960c 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -159,7 +159,7 @@ proc semIf(c: PContext, n: PNode; flags: TExprFlags): PNode = if it.len == 2: openScope(c) it[0] = forceBool(c, semExprWithType(c, it[0])) - it[1] = semExprBranch(c, it[1]) + it[1] = semExprBranch(c, it[1], flags) typ = commonType(typ, it[1]) closeScope(c) elif it.len == 1: diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim index 4535c9aac2..6857e1b57a 100644 --- a/compiler/varpartitions.nim +++ b/compiler/varpartitions.nim @@ -11,7 +11,7 @@ ## Nim's write tracking and also for the cursor inference. ## The algorithm is a reinvention / variation of Steensgaard's ## algorithm. -## The used algorithm is "union find" with path compression. +## The used data structure is "union find" with path compression. import ast, types, lineinfos, options, msgs, renderer from trees import getMagic diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim index d2bdb0fdca..00f4de5d86 100644 --- a/lib/pure/sugar.nim +++ b/lib/pure/sugar.nim @@ -394,3 +394,13 @@ when isMainModule: of "bird": "word" else: d assert z == @["word", "word"] + + + proc tforum = + let ans = collect(newSeq): + for y in 0..10: + if y mod 5 == 2: + for x in 0..y: + x + + tforum()