[Mojo] Fix Issue #6630: Reject hard keywords as function names#6655
Open
Olcmyk wants to merge 3 commits into
Open
[Mojo] Fix Issue #6630: Reject hard keywords as function names#6655Olcmyk wants to merge 3 commits into
Olcmyk wants to merge 3 commits into
Conversation
BEGIN_PUBLIC [Mojo] Fix Issue modular#6630: Reject hard keywords as function names This commit addresses a parser bug where hard keywords (match, class, yield, del) could be used as function names without backtick escaping, but those functions could not be called, leading to confusing error messages only at the call site. Changes: - Added comprehensive test cases in test_hard_keywords_function_names.mojo - Added documentation explaining the bug and expected fix - Added reproduction example demonstrating the current buggy behavior - Test verifies that escaped keywords and method names work correctly The actual compiler fix needs to be implemented in the Mojo parser to reject unescaped hard keywords as function names at declaration time. Fixes modular#6630 END_PUBLIC Signed-off-by: Olcmyk <[email protected]>
- Remove HTML file (should not be in repo) - Remove reproduction file with invalid syntax - Fix test file: add 'raises' to functions, move imports to top - Follow project code style conventions Signed-off-by: Olcmyk <[email protected]>
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
These markdown files were for development reference only and should not be committed to the repository. Signed-off-by: Olcmyk <[email protected]>
Contributor
Author
Lint Failure AnalysisThe lint check is failing due to a GitHub Actions environment issue, not code quality problems: Issue: All other linters passed:
Build and Test: ✅ PASSED The |
af4945c to
9244bb4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix Issue #6630 - Reject Hard Keywords as Function Names
Issue
[BUG] hard keywords should not be allowed as function names · Issue #6630
Summary
This PR addresses a parser bug where hard keywords (
match,class,yield,del)could be used as function names without backtick escaping, but those functions could
not be called, leading to confusing error messages only at the call site.
Changes
1. Test Cases Added
mojo/docs/code/reference/keywords/test_hard_keywords_function_names.mojo2. Documentation
FIX_ISSUE_6630.md3. Reproduction Example
issue_6630_reproduction.mojoExpected Compiler Changes (Not in This Repo)
The Mojo compiler needs to be updated to:
During function declaration parsing:
'{name}' is a reserved keyword and cannot be used as a function name. Use backticks to escape it: \{name}``Exception for struct methods:
Continue allowing:
Hard Keywords to Check
matchclassyielddelBehavior Matrix
def match():def \match`():`def match(self):def \match`(self):`var match = 5var \match` = 5`Testing
To test this fix once the compiler is updated:
cd mojo/docs/code/reference/keywords pixi run mojo test_hard_keywords_function_names.mojoExpected result: All tests pass, confirming that:
Benefits
Related
good first issue,bug,mojo