From 1e72e254105f5b167589591c87c0995d3b73d973 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:37:02 +0800 Subject: [PATCH] fixes #9839; fixes noReturn pragma doesn't work for non-simple templates (#21048) (cherry picked from commit c5eb3fd4f0798eaa31b834f5dbe3f563e55c2b03) --- compiler/semstmts.nim | 9 ++++++--- tests/controlflow/tunreachable.nim | 32 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/controlflow/tunreachable.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index d650ab3d09..3436ea0396 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -2410,9 +2410,12 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags, expectedType: PType = else: n.typ = n[i].typ if not isEmptyType(n.typ): n.transitionSonsKind(nkStmtListExpr) - if n[i].kind in nkLastBlockStmts or - n[i].kind in nkCallKinds and n[i][0].kind == nkSym and - sfNoReturn in n[i][0].sym.flags: + var m = n[i] + while m.kind in {nkStmtListExpr, nkStmtList} and m.len > 0: # from templates + m = m.lastSon + if m.kind in nkLastBlockStmts or + m.kind in nkCallKinds and m[0].kind == nkSym and + sfNoReturn in m[0].sym.flags: for j in i + 1..