summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 00:44:45 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 01:39:52 +0000
commit769d8ff1a1fd898e1a8c8b299f7e7fa444f32528 (patch)
tree8e8c19a3783b2d7633e09757d820ff180c825bd4 /src/parser
parentf88dbd3140be8733ad464b669e0c9e977a4c3a13 (diff)
Relaxed strictness for type checking.
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/parser_type.c21
-rw-r--r--src/parser/parser_utils.c3
2 files changed, 22 insertions, 2 deletions
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;