diff --git a/compiler/sem.nim b/compiler/sem.nim index ccbd665e93..b713dbbbb5 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -443,6 +443,8 @@ proc isImportSystemStmt(n: PNode): bool = else: discard proc semStmtAndGenerateGenerics(c: PContext, n: PNode): PNode = + if n.kind == nkDefer: + localError(n.info, "defer statement not supported at top level") if c.topStmts == 0 and not isImportSystemStmt(n): if sfSystemModule notin c.module.flags and n.kind notin {nkEmpty, nkCommentStmt}: