diff options
| author | Zuhaitz <zuhaitz.zechhub@gmail.com> | 2026-02-02 00:06:59 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-02 00:06:59 +0000 |
| commit | fb57d746d706fbae822de17087f4a3991d3079cb (patch) | |
| tree | bc1fcfda5db1630ed9959b8879c44ea1260aad71 /src/parser/parser_struct.c | |
| parent | fbfce63744882d48ea2fc514ab1594000254db80 (diff) | |
| parent | d51c9d091951bd4e5d2d0ccd5f72dfcbbfb412ec (diff) | |
Merge pull request #169 from iryuken/main
Disallow calling static methods with the dot operator (#168)
Diffstat (limited to 'src/parser/parser_struct.c')
| -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) { |
