diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index 09a583e..84394f3 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -1995,7 +1995,7 @@ proc assignment(self: Compiler, node: ASTNode, compile: bool = true): Type {.dis self.check(node.value, r.valueType) self.expression(node.value, compile) var position = r.position - if r.depth < self.depth: + if r.depth < self.depth and r.belongsTo != self.currentFunction: self.warning(WarningKind.MutateOuterScope, &"mutation of '{r.ident.token.lexeme}' declared in outer scope ({r.owner.file}.pn:{r.ident.token.line}:{r.ident.token.relPos.start})", nil, node) result = r.valueType if not compile: @@ -2025,7 +2025,7 @@ proc blockStmt(self: Compiler, node: BlockStmt, compile: bool = true) = if not last.isNil(): case last.kind: of breakStmt, continueStmt: - self.warning(UnreachableCode, &"code after '{last.token.lexeme}' statement is unreachable", nil, last) + self.warning(UnreachableCode, &"code after '{last.token.lexeme}' statement is unreachable", nil, decl) else: discard self.declaration(decl) @@ -2618,7 +2618,7 @@ proc namedBlock(self: Compiler, node: NamedBlockStmt) = if not last.isNil(): case last.kind: of NodeKind.breakStmt, NodeKind.continueStmt: - self.warning(UnreachableCode, &"code after '{last.token.lexeme}' statement is unreachable", nil, last) + self.warning(UnreachableCode, &"code after '{last.token.lexeme}' statement is unreachable", nil, decl) else: discard if blk.broken: @@ -2809,7 +2809,7 @@ proc funDecl(self: Compiler, node: FunDecl, name: Name) = for decl in BlockStmt(node.body).code: if not last.isNil(): if last.kind == returnStmt: - self.warning(UnreachableCode, "code after 'return' statement is unreachable") + self.warning(UnreachableCode, "code after 'return' statement is unreachable", nil, decl) self.declaration(decl) last = decl let typ = self.currentFunction.valueType.returnType diff --git a/tests/blocks.pn b/tests/blocks.pn index 5b1b866..b995a9c 100644 --- a/tests/blocks.pn +++ b/tests/blocks.pn @@ -1,7 +1,5 @@ import std; -fn foo {return;} - block outer { var x = 1;