Skip to content

Mark non-constant class and module names as non-continuable - #4447

Open
sean-garwood wants to merge 2 commits into
ruby:mainfrom
sean-garwood:fix/non-constant-name-continuable
Open

sean-garwood wants to merge 2 commits into
ruby:mainfrom
sean-garwood:fix/non-constant-name-continuable

Conversation

@sean-garwood

@sean-garwood sean-garwood commented Nov 21, 2026 •

Copy link
Copy Markdown
  • Fixes bug where classes and modules with non-constant (i.e. lowercase) names are counted as continuable.
  • Fixes bug where parse_class reported class_name twice when the name token was not a constant:
    • once for the token
    • once for the constant path node
Prism.parse("class a; end\n").continuable? # => true

Changes

Non-continuable names

pm_parse_continuable now treats class_name and module_name as 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 a can continue as class a::B; end
  • class a\n can continue as class a\n.b::C; end (ruby -c accepts 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\n non-continuable.

Duplicate parse_class errors

It now reports the node error only when the token check did not fire, the same way parse_module already does.

Tests

  • test/prism/result/continuable_test.rb: covers lowercase class and module names, the IRB input above, and the inputs that must stay continuable.
  • test/prism/errors/class_name_lowercase.txt: expects a single error for class a; end.

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 kddnewton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is missing a couple of things:

  • class a: can be followed by :B; end and become valid
  • class a # comment\n can be followed by .b::C; end and become valid
  • module # comment\n can be followed by M; end and become valid

This branch has not been deployed

No deployments
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.

2 participants