8000 Implement context validation on parse by ksss · Pull Request #2336 · ruby/rbs · GitHub
[go: up one dir, main page]

Skip to content

Implement context validation on parse #2336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

ksss
Copy link
Collaborator
@ksss ksss commented Mar 18, 2025

Contextual limitations are now performed at parse time.

This change was originally planned for version 3.4 but remained unaddressed.

We plan to change the parser to reject those types if it breaks the contextual limitations in next release -- 3.4.

I propose introducing it with the release of version 4.0.

Changes

  • The check will only be performed in Parser.parse_signature.
  • RBS::UnitTest, they have not been removed in this PR.
  • Deprecate --[no-]exit-error-on-syntax-error option.
  • Raise RBS::ParsingError instead of RBS::WillSyntaxError.
  • Remove RBS::WillSyntaxError.
  • Contextual limitations checks in the rbs validate command have been stopped.
  • Gave up analyzing CONST: self in the rbs prototype rb.

Not changes

  • I have not changed that RBS::ParsingError is raised for compatibility with Steep. It may be possible to use a different error name.
  • Parser.parse_type and Parser.parse_method_type do not currently perform checks. It might be worth adding them.
  • Since has_self_type?, has_classish_type?, and with_nonreturn_void? are used in RBS::UnitTest, they have not been removed in this PR.

@ksss ksss marked this pull request as ready for review March 19, 2025 07:54
@ksss ksss force-pushed the context-syntax-error branch from 1b1305f to 18a2b16 Compare May 22, 2025 06:47
@ksss ksss added this to the RBS 4.0 milestone May 22, 2025
@ksss
Copy link
Collaborator Author
ksss commented May 23, 2025

Rebased on master.

bool no_void_allowed_here; /* If true, `void` type is not allowed, but it's allowed in one depth.*/
bool no_self; /* If true, `self` type is not allowed.*/
bool 8000 no_classish; /* If true, `class` or `instance` types are not allowed.*/
} rbs_type_validation_t;
Copy link
Member

Choose a reason for hiding this comment

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

We might have a better name for this struct. It was a validation but now it's more tightly coupled with the parser. Something like rbs_type_parsing_option_t would be good (while it may look like too generic name...)

* */
typedef struct {
bool no_void; /* If true, `void` type is not allowed.*/
bool no_void_allowed_here; /* If true, `void` type is not allowed, but it's allowed in one depth.*/
Copy link
Member

Choose a reason for hiding this comment

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

no_void_allowed_here looks a bit too cryptic to me. Wondering if we can have a better name...

But, I'm wondering if we can merge the two void options. (I know it was from the original validation code, so I mean the original implementation was bad...)

  • Parsing function return types allows direct void types,
  • Parsing generics arguments allows direct void types,
  • Anything else prohibits void types (right?)

I'm assuming we can implement this with only one flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with you, but merging the two void options would likely result in an implementation that is no simpler—or potentially more complex—than the current one. Here are the two ideas I’ve come up with:

  • Option 1: Make no_void a type that can represent three states instead of just a bool.
  • Option 2: Add a member to the parser to retain context during parsing.

Neither of these seems like a particularly good idea.

@ksss
Copy link
Collaborator Author
ksss commented May 27, 2025

Thank you for reviewing.
I'll fix soon.

@ksss ksss force-pushed the context-syntax-error branch from 8f5dda9 to 4f7e063 Compare May 27, 2025 14:51
@ksss
Copy link
Collaborator Author
ksss commented May 27, 2025

I only renamed rbs_type_validation_t to rbs_type_parsing_option_t.

@ksss ksss requested a review from soutaro June 19, 2025 14:08
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
0