Skip to content

fix(scanner): correct implements keyword tokenization#22

Merged
ProgrammerKR merged 1 commit into
ProgrammerKR:mainfrom
bastitva0-blip:fix/implements-keyword
Jul 13, 2026
Merged

fix(scanner): correct implements keyword tokenization#22
ProgrammerKR merged 1 commit into
ProgrammerKR:mainfrom
bastitva0-blip:fix/implements-keyword

Conversation

@bastitva0-blip

Copy link
Copy Markdown
Contributor

fixes #21

fix(scanner): correct implements keyword tokenization

What was broken

The implements keyword always tokenized as TOKEN_IDENTIFIER, making interface contracts silently non-functional. The parser had correct handling ready at parser.c:471 but TOKEN_IMPLEMENTS was never produced by the scanner.

Two bugs in the same line inside identifierType() in scanner.c:

// Before — broken
if (scanner->current - scanner->start > 2 && scanner->start[2] == 'l')
    return checkKeyword(scanner, 4, 7, "ements", TOKEN_IMPLEMENTS);

Bug 1: scanner->start[2] == 'l' — wrong character. implements is i-m-p-l-e-m-e-n-t-s, so index 2 is 'p', not 'l'. This condition was never true.

Bug 2: checkKeyword(scanner, 4, 7, "ements") — wrong length. "ements" is 6 characters, not 7. Even with the character check fixed this would always fail the memcmp.

The fix

// After — correct
if (scanner->current - scanner->start > 3 &&
    scanner->start[2] == 'p' && scanner->start[3] == 'l')
    return checkKeyword(scanner, 4, 6, "ements", TOKEN_IMPLEMENTS);
  • Check start[2] == 'p' and start[3] == 'l' (the pl in im-pl-ements)
  • Guard changed to > 3 since we now read up to index 3
  • Length corrected to 6 to match "ements"

Diff

- if (scanner->current - scanner->start > 2 && scanner->start[2] == 'l')
-     return checkKeyword(scanner, 4, 7, "ements", TOKEN_IMPLEMENTS);
+ if (scanner->current - scanner->start > 3 &&
+     scanner->start[2] == 'p' && scanner->start[3] == 'l')
+     return checkKeyword(scanner, 4, 6, "ements", TOKEN_IMPLEMENTS);

File changed: src/compiler/lexer/scanner.c — 3 lines changed

Testing

// interface_test.prox
interface Greetable {
    func greet();
}

class Person implements Greetable {
    func greet() {
        print("Hello!");
    }
}

let p = new Person();
p.greet();

Before fix: implements parsed as identifier, parser errors or silently skips interface binding.
After fix: tokenizes correctly as TOKEN_IMPLEMENTS, parser enforces interface contract as expected.

@bastitva0-blip

Copy link
Copy Markdown
Contributor Author

@ProgrammerKR
Hey! Just wanted to give a quick summary of why this is safe to merge — the change is 3 lines in a single file, no logic changes anywhere else, no new dependencies, and no risk of regressions since the broken branch was literally unreachable before. The implements keyword was silently doing nothing, so this only adds behaviour that was always intended. Parser side at line 471 already handles TOKEN_IMPLEMENTS correctly — this just finally lets the scanner produce it. Happy to answer any questions!

@ProgrammerKR

Copy link
Copy Markdown
Owner

Thanks for the detailed investigation and the well-explained fix.

I reviewed the changes, and the root cause makes sense:

  • Corrected the character check from 'l' to 'p'/'l'
  • Fixed the keyword length to match "ements"

The implementation is small, focused, and aligns with the intended scanner behavior.

I'll merge this after verifying the Windows CI failure is unrelated to this change.
Thanks for your contribution!

@ProgrammerKR

Copy link
Copy Markdown
Owner

Fixed by #22.

The scanner now correctly recognizes the implements keyword and produces TOKEN_IMPLEMENTS instead of TOKEN_IDENTIFIER.

Closing this issue. Thanks to @bastitva0-blip for the contribution.

@bastitva0-blip

Copy link
Copy Markdown
Contributor Author

Hey, looks like the PR got closed instead of merged — was that intentional or did you mean to merge it? The CI failure should be unrelated to the scanner change since it's a pre-existing issue

@ProgrammerKR ProgrammerKR reopened this Jul 13, 2026
@ProgrammerKR ProgrammerKR merged commit c733fdc into ProgrammerKR:main Jul 13, 2026
4 of 6 checks passed
@bastitva0-blip

Copy link
Copy Markdown
Contributor Author

thanks for the merge @ProgrammerKR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: implements keyword always tokenized as identifier — OOP interface contracts silently broken

2 participants