Repository navigation
Mark non-constant class and module names as non-continuable - #4447
Open
sean-garwood wants to merge 2 commits into
Open
sean-garwood wants to merge 2 commits into
sean-garwood wants to merge 2 commits into
Conversation
When the name token after `class` is not a constant, parse_class reported the class_name error for the token and again for the constant path node. Only report the node error when the token check did not, matching parse_module.
A lowercase class or module name (`class a; end`) produced a class_name or module_name error that pm_parse_continuable did not treat as fatal, so the input stayed continuable forever. IRB would keep prompting for more input, even after `exit`. Treat these errors as non-continuable once anything other than whitespace follows the name. Input ending at the name stays continuable because more input can still complete it (`class a` + `::B`, or `class a\n` + `.b::C`).
kddnewton
requested changes
Nov 24, 2026
kddnewton
left a comment
Collaborator
There was a problem hiding this comment.
I think this is missing a couple of things:
class a:can be followed by:B; endand become validclass a # comment\ncan be followed by.b::C; endand become validmodule # comment\ncan be followed byM; endand become valid
This branch has not been deployed
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.
parse_classreportedclass_nametwice when the name token was not a constant:Changes
Non-continuable names
pm_parse_continuablenow treatsclass_nameandmodule_nameas non-continuable once anything other than whitespace follows the name.This extends the rules from #3978. Adding the two errors to the fatal list would not work; input that ends with a newline must stay continuable:
class acan continue asclass a::B; endclass a\ncan continue asclass a\n.b::C; end(ruby -caccepts it, and so does prism)The fatal list makes an exception only when the error ends exactly at EOF. A trailing newline would wrongly make
class a\nnon-continuable.Duplicate
parse_classerrorsIt now reports the node error only when the token check did not fire, the same way
parse_modulealready does.Tests
test/prism/result/continuable_test.rb: covers lowercaseclassandmodulenames, the IRB input above, and the inputs that must stay continuable.test/prism/errors/class_name_lowercase.txt: expects a single error forclass a; end.