diff options
| author | SAJJA EASWAR SAI <eshwarsajja20@gmail.com> | 2026-02-02 02:44:34 +0530 |
|---|---|---|
| committer | SAJJA EASWAR SAI <eshwarsajja20@gmail.com> | 2026-02-02 02:49:03 +0530 |
| commit | d51c9d091951bd4e5d2d0ccd5f72dfcbbfb412ec (patch) | |
| tree | bc1fcfda5db1630ed9959b8879c44ea1260aad71 /src/parser | |
| parent | 2ebd236e3567243f471393062dfa28d2ba53ae51 (diff) | |
Fix:#170 Detect incorrectly swapped struct and trait in impl block
Diffstat (limited to 'src/parser')
| -rw-r--r-- | src/parser/parser_struct.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/parser/parser_struct.c b/src/parser/parser_struct.c index c89ad34..0c984a6 100644 --- a/src/parser/parser_struct.c +++ b/src/parser/parser_struct.c @@ -315,6 +315,16 @@ ASTNode *parse_impl(ParserContext *ctx, Lexer *l) register_generic(ctx, target_gen_param); } + // Check for common error: swapped Struct and Trait + // impl MyStruct for MyTrait (Wrong) vs impl MyTrait for MyStruct (Correct) + if (!is_trait(name1) && is_trait(name2)) + { + zpanic_at(t1, + "Incorrect usage of impl. Did you mean 'impl %s for %s'? Syntax is 'impl " + "<Trait> for <Struct>'", + name2, name1); + } + // Auto-import std/mem.zc if implementing Drop, Copy, or Clone traits if (strcmp(name1, "Drop") == 0 || strcmp(name1, "Copy") == 0 || strcmp(name1, "Clone") == 0) { |
