From 70a429f8321be62728d5edfd63ec92af73e19915 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 8 Oct 2022 21:46:56 +0200 Subject: [PATCH] Fix error using compile time var before assignment. --- src/compiler/sema_expr.c | 5 +++++ src/compiler/sema_types.c | 2 +- src/version.h | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 465512891..4ad2183d7 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -6820,6 +6820,11 @@ static inline bool sema_cast_ct_ident_rvalue(SemaContext *context, Expr *expr) { Decl *decl = expr->ct_ident_expr.decl; Expr *copy = copy_expr_single(decl->var.init_expr); + if (!copy) + { + SEMA_ERROR(expr, "'%s' was not yet initialized to any value, assign a value to it before use.", decl->name); + return false; + } if (!sema_analyse_expr(context, copy)) return false; expr_replace(expr, copy); return true; diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index a222aa1ba..5cd9b3b71 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -175,7 +175,7 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in { if (!decl->var.init_expr) { - SEMA_ERROR(type_info, "The variable '%s' is not defined yet.", decl->name); + SEMA_ERROR(type_info, "You need to assign a type to '%s' before using it.", decl->name); return false; } assert(decl->var.init_expr->expr_kind == EXPR_TYPEINFO); diff --git a/src/version.h b/src/version.h index 212a4e1e7..e27ed61fe 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.76" \ No newline at end of file +#define COMPILER_VERSION "0.3.77" \ No newline at end of file