summaryrefslogtreecommitdiff
path: root/src/parser/parser_type.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 14:38:28 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 14:38:28 +0000
commit8b720543f538862796fec0ff6b7ea12cb140bf0f (patch)
tree0f4a20d305842ffed01cdd9536fd937d82cd76d4 /src/parser/parser_type.c
parent0bd7b99fbf813415b9a0217eaa2a4e8f6f74e1ea (diff)
Fix for #90
Diffstat (limited to 'src/parser/parser_type.c')
-rw-r--r--src/parser/parser_type.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c
index 5774571..0585baa 100644
--- a/src/parser/parser_type.c
+++ b/src/parser/parser_type.c
@@ -751,14 +751,31 @@ Type *parse_type_formal(ParserContext *ctx, Lexer *l)
}
}
+ Type *t = NULL;
+
// Example: fn(int, int) -> int
if (lexer_peek(l).type == TOK_IDENT && strncmp(lexer_peek(l).start, "fn", 2) == 0 &&
lexer_peek(l).len == 2)
{
lexer_next(l); // eat 'fn'
+
+ int star_count = 0;
+ while (lexer_peek(l).type == TOK_OP && strncmp(lexer_peek(l).start, "*", 1) == 0)
+ {
+ lexer_next(l);
+ star_count++;
+ }
+
Type *fn_type = type_new(TYPE_FUNCTION);
+ fn_type->is_raw = (star_count > 0);
fn_type->is_varargs = 0;
+ Type *wrapped = fn_type;
+ for (int i = 1; i < star_count; i++)
+ {
+ wrapped = type_new_ptr(wrapped);
+ }
+
expect(l, TOK_LPAREN, "Expected '(' for function type");
// Parse Arguments
@@ -794,11 +811,13 @@ Type *parse_type_formal(ParserContext *ctx, Lexer *l)
fn_type->inner = type_new(TYPE_VOID);
}
- return fn_type;
+ t = wrapped;
+ }
+ else
+ {
+ // Handles: int, Struct, Generic<T>, [Slice], (Tuple)
+ t = parse_type_base(ctx, l);
}
-
- // Handles: int, Struct, Generic<T>, [Slice], (Tuple)
- Type *t = parse_type_base(ctx, l);
// Handles: T*, T**, etc.
while (lexer_peek(l).type == TOK_OP && *lexer_peek(l).start == '*')