summaryrefslogtreecommitdiff
path: root/test/prism/errors_test.rb
AgeCommit message (Collapse)Author
2025-12-02[ruby/prism] Clean up test excludesEarlopain
Mostly not having to list version-specific excludes when testing against ripper/parse.y Also don't test new syntax additions against the parser gems. The version support for them may (or may not) be expanded but we shouldn't bother while the ruby version hasn't even released yet. (ruby_parser translation is not versioned, so let as is for now) I also removed excludes that have since been implemented by parse.y https://github.com/ruby/prism/commit/e5a0221c37
2025-11-20[ruby/prism] Add tests to `regexp_encoding_option_mismatch`Thiago Araujo
related to #2667 https://github.com/ruby/prism/commit/44f075bae4
2025-10-22[ruby/prism] Make error and snapshot tests multi-version awareEarlopain
This one has been on my mind for a while now. Currently, there are only tests against the latest syntax version. This changes the snapshot structure as follows: * Snapshots at their current location are tested against all syntax versions * Snapshots inside a version folder like "3.3" are tested against all versions starting from that version * Snapshots inside a version folder like "3.3-4.2" are tested against all versions in the given range. This makes sure that as new syntax is added, older versions still work as expected. I also added a few tests for now valid syntax that should be invalid in older versions (and the other way around as well) These tests run really fast. So even though it does 3x the work for these, I am still able to run the whole test suite in just 11 seconds. https://github.com/ruby/prism/commit/5191b1aa68
2025-09-12[ruby/prism] [Bug #17398] Allow `private def hello = puts "Hello"`Earlopain
This was a limitation of parse.y that prism intentionally replicated. https://github.com/ruby/prism/commit/8fd12d594c
2025-02-13[ruby/prism] No writing to numbered parametersKevin Newton
Fixes [Bug #21117] https://github.com/ruby/prism/commit/19d4bab5a0
2024-12-16[ruby/prism] Blocks & kwargs are not valid in index assignmentsMatt Valentine-House
Ruby feature: https://bugs.ruby-lang.org/issues/20952 https://github.com/ruby/prism/commit/e612df5f36
2024-12-05[ruby/prism] Fix error messages for unterminated ( and {Aaron Patterson
If we hit an EOF token, and the character before the EOF is a newline, we should make EOF token start at the previous newline. That way any errors reported will occur on that line. For example "foo(\n" should report an error on line 1 even though the EOF technically occurs on line 2. [Bug #20918] https://bugs.ruby-lang.org/issues/20918 https://github.com/ruby/prism/commit/60bc43de8e
2024-07-25[ruby/prism] Sync from ruby/rubyKevin Newton
https://github.com/ruby/prism/commit/280517c325
2024-07-11[ruby/prism] Various cleanup for initializers and typechecksKevin Newton
https://github.com/ruby/prism/commit/86cf82794a
2024-07-11[ruby/prism] Reconfigure error testsKevin Newton
https://github.com/ruby/prism/commit/fb7e1ebb7f
2024-06-26[ruby/prism] Handle block exits under modifiersKevin Newton
https://github.com/ruby/prism/commit/6b78f5309b
2024-06-14[ruby/prism] Ensure ranges are non-associativeKevin Newton
https://github.com/ruby/prism/commit/f59295938b
2024-06-11[ruby/prism] Match CRuby error message for unknown regexp optionsKevin Newton
https://github.com/ruby/prism/commit/73669b59f6
2024-06-06Remove circular parameter syntax errorKevin Newton
https://bugs.ruby-lang.org/issues/20478
2024-05-30[ruby/prism] Tests overhaulKevin Newton
https://github.com/ruby/prism/commit/6f886be0a4
2024-05-23[ruby/prism] Raise `void value expression` in begin clauseseileencodes
In some cases Prism was either not raising an appropriate `void value expression` error, or raising that error when the syntax is considered valid. To fix this Prism needs to check whether we have other clauses on the `begin` rather than just returning `cast->statements`. * If the `cast->statements` are null and the `cast->ensure_clause` is not null, set the code to `cast->ensure_clause` * else * If there is a `cast->rescue_clause` * Check if `cast->statements` are null and `cast->rescue_clause->statements` are null, and return `NULL` * Check if there is an `else_clause`, and set the node to `cast->else_clause`. * Otherwise return `cast->statements` as the node * return `cast->statements` as the node See tests for test cases. Note I took these directly from CRuby so if desired I can delete them since the test will now pass. This only fixes one test in the `test_parse` file, taking failures from 14 to 13. This fixes `TestParse#test_void_value_in_rhs` and is related to issue #2791. https://github.com/ruby/prism/commit/398152b412
2024-05-22[ruby/prism] Fix support for 'it' implicit local variableKevin Newton
https://github.com/ruby/prism/commit/53bbcfe513
2024-05-21[ruby/prism] Add error for numbered parameter used in inner blockKevin Newton
https://github.com/ruby/prism/commit/c386ba6d48
2024-05-16[ruby/prism] Update more escape error messages to match CRubyKevin Newton
https://github.com/ruby/prism/commit/ab43b3ab66
2024-05-16[ruby/prism] Update error message for invalid % at EOFKevin Newton
https://github.com/ruby/prism/commit/178d4f66fd
2024-05-16[ruby/prism] Match CRuby error message for unknown % stringKevin Newton
https://github.com/ruby/prism/commit/863197629c
2024-05-16[ruby/prism] Always go to string lex mode even if EOFKevin Newton
https://github.com/ruby/prism/commit/57d5c9be2c
2024-05-15[ruby/prism] Replace end of file with end-of-inputKevin Newton
https://github.com/ruby/prism/commit/dd532ded95
2024-05-10[ruby/prism] Enhance parameter forwarding error messagesKevin Newton
https://github.com/ruby/prism/commit/826657232e
2024-05-07[ruby/prism] Extend error message for unterminated HEREDOCKevin Newton
https://github.com/ruby/prism/commit/c1b07ec11b
2024-05-03[ruby/prism] Disallow keywords and blocks in index expressionsKevin Newton
https://github.com/ruby/prism/commit/e950dc1e83
2024-05-01[PRISM] Fix up error message expectationsKevin Newton
2024-05-01[ruby/prism] CRuby error message for trailing underscore in numberKevin Newton
https://github.com/ruby/prism/commit/4e34f236d3
2024-04-26[ruby/prism] Add a flag on returns when they are redundantKevin Newton
https://github.com/ruby/prism/commit/450541d2c3
2024-04-12[ruby/prism] Better error message on statement inside argument listKevin Newton
https://github.com/ruby/prism/commit/3b1a99526a
2024-04-12[ruby/prism] Better error message on invalid defKevin Newton
https://github.com/ruby/prism/commit/d398e7d22c
2024-04-12[ruby/prism] Syntax error for block argument on yieldKevin Newton
https://github.com/ruby/prism/commit/9feeafbc67
2024-04-12[ruby/prism] Fix up embdoc lexing on EOFKevin Newton
https://github.com/ruby/prism/commit/8ee43be26d
2024-04-09[ruby/prism] Fix up invalid global variable error messageKevin Newton
https://github.com/ruby/prism/commit/8ce9ae487f
2024-04-05[ruby/prism] Replace old circular parameter definition detectionKevin Newton
https://github.com/ruby/prism/commit/c739f8e194
2024-04-04[ruby/prism] Change forwarding error messages to match CRubyKevin Newton
https://github.com/ruby/prism/commit/6a15e475c9
2024-04-03[ruby/prism] Allow block exits in defined? and fix modifier while/untilKevin Newton
https://github.com/ruby/prism/commit/2752f0b8df
2024-04-03[ruby/prism] Check for syntax errors using RubyVMKevin Newton
https://github.com/ruby/prism/commit/9e200dd1c1
2024-04-03[ruby/prism] Fix up errors testKevin Newton
https://github.com/ruby/prism/commit/5f86742537
2024-04-03[ruby/prism] Match circular parameter error messageKevin Newton
https://github.com/ruby/prism/commit/c0381b10e4
2024-04-01[ruby/prism] Match more error messagesKevin Newton
https://github.com/ruby/prism/commit/0cc3a9d63a
2024-04-01[ruby/prism] Do not track locals starting with _Kevin Newton
https://github.com/ruby/prism/commit/0d5a6d936a
2024-04-01[ruby/prism] Use RubyVM::InstructionSequence instead of Ripper for validity ↵Kevin Newton
check https://github.com/ruby/prism/commit/ddec1c163d
2024-04-01[ruby/prism] Track duplicate hash keys for pattern matchingKevin Newton
https://github.com/ruby/prism/commit/71ea82f299
2024-04-01[ruby/prism] Track captures in pattern matching for duplicatesKevin Newton
https://github.com/ruby/prism/commit/aa2182f064
2024-03-29[PRISM] Fix error message for duplicate parameter nameKevin Newton
2024-03-26[ruby/prism] Fix an incorrect range of `Prism::Location` when ↵Koichi ITO
`PM_ERR_RETURN_INVALID` This PR fixes the following incorrect range of `Prism::Location` when `PM_ERR_RETURN_INVALID`. It may be hard to tell from the text, but this Ruby error highlights `return`: ```console $ ruby -e 'class Foo return end' -e:1: Invalid return in class/module body class Foo return end -e: compile error (SyntaxError) ``` Previously, the error's `Prism::Location` pointed to `end`: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("class Foo return end").errors' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:return_invalid @message="invalid `return` in a class or module body" @location=#<Prism::Location @start_offset=17 @length=3 start_line=1> @level=:fatal>] After this fix, it will indicate `return`. ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("class Foo return end").errors' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:return_invalid @message="invalid `return` in a class or module body" @location=#<Prism::Location @start_offset=10 @length=6 start_line=1> @level=:fatal>] ``` For reference, here are the before and after of `Prism::Translation::Parser`. Before: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("class Foo return end")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] (string):1:18: error: invalid `return` in a class or module body (string):1: class Foo return end (string):1: ^~~ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72:in `process': invalid `return` in a class or module body (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:220:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` After: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("class Foo return end")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] (string):1:11: error: invalid `return` in a class or module body (string):1: class Foo return end (string):1: ^~~~~~ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72:in `process': invalid `return` in a class or module body (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:220:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` This PR ensures that the originally intended `return` is highlighted as it should be. https://github.com/ruby/prism/commit/1f9af4d2ad
2024-03-25[ruby/prism] Fix incorrect paring when using invalid regexp optionsKoichi ITO
Fixes https://github.com/ruby/prism/pull/2617. There was an issue with the lexer as follows. The following are valid regexp options: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/io").value.map {|token| token[0].type }' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :EOF] ``` The following are invalid regexp options. Unnecessary the `IDENTIFIER` token is appearing: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/az").value.map {|token| token[0].type }' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :IDENTIFIER, :EOF] ``` As a behavior of Ruby, when given `A` to `Z` and `a` to `z`, they act as invalid regexp options. e.g., ```console $ ruby -e '/regexp/az' -e:1: unknown regexp options - az /regexp/az -e: compile error (SyntaxError) ``` Thus, it should probably not be construed as `IDENTIFIER` token. Therefore, `pm_byte_table` has been adapted to accept those invalid regexp option values. Whether it is a valid regexp option or not is checked by `pm_regular_expression_flags_create`. For invalid regexp options, `PM_ERR_REGEXP_UNKNOWN_OPTIONS` is added to diagnostics. https://github.com/ruby/prism/commit/d2a6096fcf
2024-03-12[ruby/prism] Consolidate warnings for conditional predicatesKevin Newton
* Also add warnings for literals in predicates * Also create flip-flops in while/until https://github.com/ruby/prism/commit/a6b5c523c2
2024-02-22[ruby/prism] Add an IntegerField for parsing integer valuesKevin Newton
https://github.com/ruby/prism/commit/120d8c0479