Skip to content
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

Ruby -c does not detect unsupported syntax (false positive) #3330

Closed
sempervictus opened this issue Nov 26, 2023 · 5 comments
Closed

Ruby -c does not detect unsupported syntax (false positive) #3330

sempervictus opened this issue Nov 26, 2023 · 5 comments
Assignees

Comments

@sempervictus
Copy link

Running /usr/lib/jvm/java-21-graalvm/bin/ruby -c somefile.rb produces Syntax OK despite the file containing pattern-matching case statements which the interpreter cannot resolve (syntax error, unexpected keyword_in). This creates a false positive for tests trying to ensure that the resulting application is TruffleRuby-compatible.

@sempervictus
Copy link
Author

This seems a bit more nefarious than i previously thought - https://github.com/oracle/truffleruby/blob/master/doc/user/compatibility.md does not seem to mention the whole "TruffleRuby doesnt do pattern matches" piece which is a pretty big deal especially when the interpreter validates the syntax.

Is there an effort somewhere to get this working?

@eregon
Copy link
Member

eregon commented Nov 27, 2023

ruby -c is a very weak check, in fact it only runs the parser but the not the compiler (from parser AST to another AST or to bytecode).
A simple example:

$ ruby -v -e 'break'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
-e:1: Invalid break
-e: compile error (SyntaxError)

$ ruby -v -c -e 'break'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Syntax OK

And the fact is the current parser can parse pattern matching but it's not fully implemented yet (#3332) so that specific result is expected and -c basically should be like it is for compatibility with CRuby.

Indeed, https://github.com/oracle/truffleruby/blob/master/doc/user/compatibility.md misses to mention that, I will update it. Array pattern matching is already supported with the --pattern-matching flag, hash pattern matching not yet, we'll finish #3117 first.

@eregon
Copy link
Member

eregon commented Nov 27, 2023

Docs updated in e16a0c2

@eregon eregon closed this as completed Nov 27, 2023
@eregon eregon self-assigned this Nov 27, 2023
@sempervictus
Copy link
Author

Thank you for the detailed explanation - looking forward to common parser and full(ish) compatibility with MRI syntax. Been a while since i've been free of the GIL in production.

@eregon
Copy link
Member

eregon commented Jan 28, 2024

Fixed for 24.0

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

No branches or pull requests

2 participants