aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-14 23:08:01 +0900
committernsfisis <nsfisis@gmail.com>2026-01-17 00:27:27 +0900
commitc37878302934f9d372e327612bef37da1c8e3a65 (patch)
tree5ca9e118866f870253f36dff4be49e4bf9f0ac4a
parenteca1a0d51e7c8fc4855d0303c17ed8c740d595d6 (diff)
downloadducc-c37878302934f9d372e327612bef37da1c8e3a65.tar.gz
ducc-c37878302934f9d372e327612bef37da1c8e3a65.tar.zst
ducc-c37878302934f9d372e327612bef37da1c8e3a65.zip
feat: add source location to error messages for undefined symbols
-rw-r--r--src/parse.c4
-rw-r--r--tests/compile_errors.sh2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/parse.c b/src/parse.c
index d590df6..2818082 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -385,7 +385,7 @@ static AstNode* parse_primary_expr(Parser* p) {
AstNode* e = ast_new(AstNodeKind_func_call);
int func_idx = find_func(p, name);
if (func_idx == -1) {
- fatal_error("undefined function: %s", name);
+ fatal_error("%s:%d: undefined function: %s", t->loc.filename, t->loc.line, name);
}
e->name = name;
e->ty = p->funcs.data[func_idx].ty->result;
@@ -400,7 +400,7 @@ static AstNode* parse_primary_expr(Parser* p) {
if (enum_member_idx == -1) {
int func_idx = find_func(p, name);
if (func_idx == -1) {
- fatal_error("undefined variable: %s", name);
+ fatal_error("%s:%d: undefined variable: %s", t->loc.filename, t->loc.line, name);
}
AstNode* e = ast_new(AstNodeKind_func);
e->name = name;
diff --git a/tests/compile_errors.sh b/tests/compile_errors.sh
index c41d633..e99282b 100644
--- a/tests/compile_errors.sh
+++ b/tests/compile_errors.sh
@@ -1,5 +1,5 @@
cat <<'EOF' > expected
-undefined function: f
+main.c:2: undefined function: f
EOF
test_compile_error <<'EOF'
int main() {