diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 5e2c2bccc1..931ff5554b 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -722,7 +722,11 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = of nkBracketExpr: result = foldArrayAccess(m, n, g) of nkDotExpr: result = foldFieldAccess(m, n, g) of nkStmtListExpr: - if n.len == 2 and n[0].kind == nkComesFrom: - result = getConstExpr(m, n[1], g) + var i = 0 + while i <= n.len - 2: + if n[i].kind in {nkComesFrom, nkCommentStmt, nkEmpty}: i.inc + else: break + if i == n.len - 1: + result = getConstExpr(m, n[i], g) else: discard diff --git a/tests/types/tyet_another_generic_regression.nim b/tests/types/tyet_another_generic_regression.nim index 0839937570..2e5f9bb238 100644 --- a/tests/types/tyet_another_generic_regression.nim +++ b/tests/types/tyet_another_generic_regression.nim @@ -30,3 +30,12 @@ const }.toTable #map["test"]() + +#------------------------------------------------------------------- +# bug +const val = 10 + +type + t = object + when val >= 10: + a: int