From 958cab54523a3c5a7c53daae502bfbf9b0caec1e Mon Sep 17 00:00:00 2001 From: liquidev Date: Sat, 7 Sep 2024 14:30:58 +0200 Subject: [PATCH] improve error reporting for missing `else` clauses --- crates/haku/src/parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/haku/src/parser.rs b/crates/haku/src/parser.rs index c8b89d2..a9793fb 100644 --- a/crates/haku/src/parser.rs +++ b/crates/haku/src/parser.rs @@ -497,6 +497,7 @@ fn lambda(p: &mut Parser) -> Closed { fn if_expr(p: &mut Parser) -> Closed { let o = p.open(); + let if_span = p.span(); p.advance(); // if if p.peek() != TokenKind::LParen { let span = p.span(); @@ -522,9 +523,8 @@ fn if_expr(p: &mut Parser) -> Closed { p.optional_newline(); if p.peek() != TokenKind::Else { - let span = p.span(); p.emit(Diagnostic::error( - span, + if_span, "`if` expression is missing an `else` clause", )); }