From 769d8ff1a1fd898e1a8c8b299f7e7fa444f32528 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sat, 24 Jan 2026 00:44:45 +0000 Subject: Relaxed strictness for type checking. --- src/parser/parser_type.c | 21 +++++++++++++++++++++ src/parser/parser_utils.c | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/parser') diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c index 24e9f69..39a4dc7 100644 --- a/src/parser/parser_type.c +++ b/src/parser/parser_type.c @@ -439,6 +439,14 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) return type_new(TYPE_ISIZE); } + // Relaxed Type Check: If explicit 'struct Name', trust the user. + if (explicit_struct) + { + Type *ty = type_new(TYPE_STRUCT); + ty->name = name; + ty->is_explicit_struct = 1; + } + // Selective imports ONLY apply when we're NOT in a module context if (!ctx->current_module_prefix) { @@ -707,6 +715,19 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) return ty; } + // If we have an identifier that wasn't found, + // assume it is a valid external C type + // (for example, a struct defined in implementation). + if (t.type == TOK_IDENT) + { + char *fallback = token_strdup(t); + lexer_next(l); + Type *ty = type_new(TYPE_STRUCT); + ty->name = fallback; + ty->is_explicit_struct = 0; + return ty; + } + return type_new(TYPE_UNKNOWN); } diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index a11324d..0b47d2a 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -3468,8 +3468,7 @@ int validate_types(ParserContext *ctx) SelectiveImport *si = find_selective_import(ctx, u->name); if (!si && !is_trait(u->name)) { - zpanic_at(u->location, "Unknown type '%s'", u->name); - errors++; + zwarn_at(u->location, "Unknown type '%s' (assuming external C struct)", u->name); } } u = u->next; -- cgit v1.2.3