Minor improvements to warning messages

This commit is contained in:
Mattia Giambirtone 2022-12-09 13:40:02 +01:00
parent e87428b85d
commit f86925edba
2 changed files with 4 additions and 6 deletions

View File

@ -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

View File

@ -1,7 +1,5 @@
import std;
fn foo {return;}
block outer {
var x = 1;