From 0069d6668ae6c1d18d3bc1e598af4bdb2ebbf2dc Mon Sep 17 00:00:00 2001 From: cooldome Date: Thu, 27 Feb 2020 17:02:52 +0000 Subject: [PATCH] fix #13490 --- compiler/ast.nim | 2 ++ compiler/sem.nim | 2 +- compiler/semstmts.nim | 7 ++----- compiler/vmgen.nim | 2 -- tests/casestmt/tcasestmt.nim | 37 ++++++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 5938d4e53808..70c14ccaf185 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -336,6 +336,8 @@ const tagEffects* = 3 # user defined tag ('gc', 'time' etc.) pragmasEffects* = 4 # not an effect, but a slot for pragmas in proc type effectListLen* = 5 # list of effects list + nkLastBlockStmts* = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt} + # these must be last statements in a block type TTypeKind* = enum # order is important! diff --git a/compiler/sem.nim b/compiler/sem.nim index 7cd0aa6f2079..18e0ec532187 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -181,7 +181,7 @@ proc endsInNoReturn(n: PNode): bool = var it = n while it.kind in {nkStmtList, nkStmtListExpr} and it.len > 0: it = it.lastSon - result = it.kind == nkRaiseStmt or + result = it.kind in nkLastBlockStmts or it.kind in nkCallKinds and it[0].kind == nkSym and sfNoReturn in it[0].sym.flags proc commonType*(x: PType, y: PNode): PType = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 7636705e0e6b..deffe563c9bf 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -120,7 +120,7 @@ const proc implicitlyDiscardable(n: PNode): bool = var n = n while n.kind in skipForDiscardable: n = n.lastSon - result = n.kind == nkRaiseStmt or + result = n.kind in nkLastBlockStmts or (isCallExpr(n) and n[0].kind == nkSym and sfDiscardable in n[0].sym.flags) @@ -2162,9 +2162,6 @@ proc inferConceptStaticParam(c: PContext, inferred, n: PNode) = typ.n = res proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = - # these must be last statements in a block: - const - LastBlockStmts = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt} result = n result.transitionSonsKind(nkStmtList) var voidContext = false @@ -2209,7 +2206,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = else: n.typ = n[i].typ if not isEmptyType(n.typ): n.transitionSonsKind(nkStmtListExpr) - if n[i].kind in LastBlockStmts or + 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: for j in i + 1..