Commit graph

18546 commits

Author SHA1 Message Date
Matt Valentine-House
57782d3d47 Store depth offset inside the scope node.
Instead of incrementing the depth using call by reference as we're
recursing up the stack we could instead store an offset for each known
scope where we know the depth is going to represented differently in the
Prism ast.
2023-11-30 21:31:57 +00:00
Ellen Marie Dash
7008d97b76 [rubygems/rubygems] Only show "Defaulting to user installation" message when it matters.
61b0947225
2023-11-30 19:58:40 +00:00
Stan Lo
f193f96d31 [ruby/irb] Page evaluation result's output
(https://github.com/ruby/irb/pull/784)

* Page evaluation result's output

This will make it easier to work with long output that exceeds the terminal's height.

* Use consistent TERM in rendering tests

This makes sure we get consistent result on all platforms.

4fedce93d3
2023-11-30 15:22:22 +00:00
Nobuyoshi Nakada
cc393b4f80 [ruby/rdoc] Get rid of Kernel#open
dc56f6d0bd
2023-11-30 15:06:51 +00:00
Aaron Patterson
630c97acc7 Add a rescue for defined?(A::B::C)
It's possible for `defined?(A::B::C)` to raise an exception.  `defined?`
must swallow the exception and return nil, so this commit adds a rescue
entry for `defined?` expressions on constant paths
2023-11-30 09:48:14 -05:00
Martin Emde
aac8be8034 [ruby/prism] Fix lex_compat for <<HEREDOC # comment at EOF
Fixes https://github.com/ruby/prism/pull/1874

304dd78dd2
2023-11-30 14:10:04 +00:00
Nobuyoshi Nakada
1802d14ca8 [Bug #19877] Assign captures for direct regexp literal only 2023-11-30 21:40:22 +09:00
OKURA Masafumi
18f218d6a1 Add some test cases to Data test
I noticed that `deconstruct` and `hash` don't have enough coverage.
The behavior of `hash` is documented so I copied it.
2023-11-30 21:35:04 +09:00
Hiroshi SHIBATA
722cb9a56d
Skip test_resolurion_error_error_code with FreeBSD environment
20231130T103002Z.fail.html.gz
2023-11-30 20:17:27 +09:00
flosacca
0daa0589a9 [ruby/cgi] Add failing test cases for CGI::Escape.unescapeHTML
92fdb3316b
2023-11-30 08:19:28 +00:00
Nobuyoshi Nakada
e6d4441618
Fix the argument order 2023-11-30 13:36:11 +09:00
Misaki Shioi
52f6de4196 Replace SocketError with Socket::ResolutionError in rsock_raise_socket_error
rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
2023-11-30 13:27:19 +09:00
Peter Zhu
3d908a41ab Guard match from GC in String#gsub
We need to guard match from GC because otherwise it could end up being
reclaimed or moved in compaction.
2023-11-29 19:21:40 -05:00
Jemma Issroff
853fd44745 [PRISM] Implement CallNodes with splat followed by args 2023-11-29 16:19:14 -05:00
Jemma Issroff
2233204cc1 [PRISM] Account for ImplicitRestNode
Prism introduced a new ImplicitRestNode. This adds tests for the
ImplicitRestNode cases, and changes one assert which is no longer
accurate.
2023-11-29 16:14:28 -05:00
Jemma Issroff
53841941f0 [PRISM] Fix EnsureNode, pass depth to get locals
This commit fixes a bug with locals in ensure nodes by setting
the local tables correctly. It also changes accessing locals to
look at local tables in parent scopes, and account for this
correctly on depths of get or setlocals.
2023-11-29 16:00:00 -05:00
Matt Boldt
9fc40d2b26 [ruby/prism] Add MacJapanese encoding
MacJapanese (also aliased as MacJapan) is a modified Shift_JIS
encoding, but is implemented identically in Ruby

9e0a097699
2023-11-29 12:08:15 -05:00
tomoya ishida
86d9a6dcb6 [ruby/irb] Use gem repl_type_completor, remove type_completion
implementation
(https://github.com/ruby/irb/pull/772)

a4868a5373
2023-11-29 16:30:13 +00:00
Dhaval
9fada99cb2 [ruby/prism] added CP950 encoding
9c2d1cf4ba
2023-11-29 11:15:50 -05:00
Peter Zhu
38e6442f8c Add missing assertion in test_use_all_shapes_then_freeze 2023-11-29 08:59:53 -05:00
Jean Boussier
2af82e2316 [ruby/prism] Convert start line to signed integers
Ruby allows for 0 or negative line start, this is often used
with `eval` calls to get a correct offset when prefixing a snippet.

e.g.

```ruby
caller = caller_locations(1, 1).first
class_eval <<~RUBY, caller.path, caller.line - 2
  # frozen_string_literal: true
  def some_method
    #{caller_provided_code_snippet}
  end
RUBY
```

0d14ed1452
2023-11-29 13:56:19 +00:00
Nobuyoshi Nakada
8e93bf8e1f
[Bug #17037] Improve accuracy of division near precision limits
When dividing near the precision limit of `double`, use Bignum
division to get rid of rounding errors.
2023-11-29 20:16:36 +09:00
Nobuyoshi Nakada
79eb75a8dd
[Bug #20025] Check if upper/lower before fallback to case-folding 2023-11-29 14:40:21 +09:00
TSUYUSATO Kitsune
a908cef53f [ruby/prism] Reject class/module defs in method params/rescue/ensure/else
Fix https://github.com/ruby/prism/pull/1936

232e77a003
2023-11-29 02:03:06 +00:00
Tema Bolshakov
e4a11a1283 Array#rassoc should try to convert to array implicitly. Fixes #20003 2023-11-29 09:39:15 +09:00
Peter Zhu
10f44dfeff Fix Ractor sharing for too complex Objects 2023-11-28 17:43:22 -05:00
Peter Zhu
6eb5a9cf8f Fix Ractor sharing for too complex generic ivars 2023-11-28 17:43:22 -05:00
Kevin Newton
4938390177 [ruby/prism] Implicit rest nodes
Fundamentally, `foo { |bar,| }` is different from `foo { |bar, *| }`
because of arity checks. This PR introduces a new node to handle
that, `ImplicitRestNode`, which goes in the `rest` slot of parameter
nodes instead of `RestParameterNode` instances.

This is also used in a couple of other places, namely:

* pattern matching: `foo in [bar,]`
* multi target: `for foo, in bar do end`
* multi write: `foo, = bar`

Now the only splat nodes with a `NULL` value are when you're
forwarding, as in: `def foo(*) = bar(*)`.

dba2a3b652
2023-11-28 22:33:50 +00:00
Jemma Issroff
a9c07cbd21 [PRISM] Don't calculate params size based on locals
Prior to this commit, we were conflating the size of the locals
list with the number of parameters. This commit distinguishes
the two, and fixes a related bug which would occur if we set a local
that was not a parameter
2023-11-28 17:01:34 -05:00
Jemma Issroff
04cbcd37b1 [ruby/prism] Add numbered_parameters field to BlockNode and LambdaNode
We are aware at parse time how many numbered parameters we have
on a BlockNode or LambdaNode, but prior to this commit, did not
store that information anywhere in its own right.

The numbered parameters were stored as locals, but this does not
distinguish them from other locals that have been set, for example
in `a { b = 1; _1 }` there is nothing on the AST that distinguishes
b from _1.

Consumers such as the compiler need to know information about how
many numbered parameters exist to set up their own tables around
parameters. Since we have this information at parse time, we should
compute it here, instead of deferring the work later on.

bf4a1e124d
2023-11-28 21:08:46 +00:00
Jean Boussier
982641939c Further fix the GVL instrumentation API
Followup: https://github.com/ruby/ruby/pull/9029

[Bug #20019]

Some events still weren't triggered from the right place.

The test suite was also improved a bit more.
2023-11-28 20:06:55 +01:00
Jemma Issroff
7bd172744f [PRISM] Implement more compilation of SplatNodes
There was a bug with the rest argument in SplatNodes, this commit
fixes it, and adds more tests illustrating the behavior of
SplatNodes
2023-11-28 14:03:57 -05:00
Jemma Issroff
2760f23774 [PRISM] Compile YieldNode with different arguments 2023-11-28 14:02:53 -05:00
Alan Wu
cd4207869f Fix cache incoherency for ME resolved through VM_METHOD_TYPE_REFINED
Previously, we didn't invalidate the method entry wrapped by
VM_METHOD_TYPE_REFINED method entries which could cause calls to
land in the wrong method like it did in the included test.

Do the invalidation, and adjust rb_method_entry_clone() to accommodate
this new invalidation vector.

Fix: cfd7729ce7
See-also: e201b81f79
2023-11-28 13:03:04 -05:00
Alan Wu
7b05721167 [PRISM] Run test setting global constant separately
This impacted other tests. Please mind the commons.

      /home/runner/work/ruby/ruby/src/test/ruby/test_compile_prism.rb:394: warning: already initialized constant Bar
      /tmp/test_reline_config_60145/bazbarbob.rb:6: warning: previous definition of Bar was here

        1) Failure:
      TestModule#test_const_get_evaled [/home/runner/work/ruby/ruby/src/test/ruby/test_module.rb:1239]:
      NameError expected but nothing was raised.
2023-11-28 12:30:30 -05:00
TSUYUSATO Kitsune
55f34d4745 [ruby/prism] Fix tests
1e6ecbaf04
2023-11-28 17:27:11 +00:00
TSUYUSATO Kitsune
c11dd34753 [ruby/prism] Reset current_param_name around closed scopes
It is for supporting `def foo(bar = (def baz(bar) = bar; 1)) = 2` case.

c789a833c5
2023-11-28 17:27:10 +00:00
TSUYUSATO Kitsune
f6fbb9fec5 [ruby/prism] Use 0 for the default valie of current_param_name
896915de24
2023-11-28 17:27:10 +00:00
TSUYUSATO Kitsune
b5796d7b11 [ruby/prism] Check circular references in default values of params
Fix https://github.com/ruby/prism/pull/1637

0172d69cba
2023-11-28 17:27:09 +00:00
Peter Zhu
fadd28c7ba [ruby/irb] Change show_source tests into integration tests
* Remove trailing spaces

* Migrate show_source tests to integration tests

Because show_source tests often need to define class and/or methods,
they can easily leak state to other tests. Changing them to integration
tests will ensure that they are run in a clean environment.

* Fix NoMethodError caused by SourceFinder#method_target

3c39f13397
2023-11-28 12:22:46 -05:00
paulreece
891ce4614a [ruby/irb] This enhancement allows a user to add the -s flag if they
want to access a methods origin definition.  It allows for chaining
of multiple esses to further go up the classes as needed.
(https://github.com/ruby/irb/pull/770)

eec1329d5a
2023-11-28 14:56:51 +00:00
Kasumi Hanazuki
5fc71feb6c [ruby/irb] Rescue errors from main.to_s/inspect when formatting
prompt
(https://github.com/ruby/irb/pull/791)

Currently, IRB just terminates if `main.to_s` raises while IRB
constructs the prompt string. This can easily happen if the user wants
to start an IRB session in the instance scope of an uninitialized
object, for example:

```
class C
  def initialize
    binding.irb
    @values = []
  end

  def to_s = @values.join(',')  # raises if uninitialized
end

C.new
```

This patch makes IRB rescue from such an exception and displays the
class name of the exception instead of `main.to_s` to indicate some
error has occurred.

We may display more detailed information about the exception, but this
patch chooses not to do so because 1) the prompt has limited space,
2) users can evaluate `to_s` in IRB to examine the error if they want,
and 3) obtaining the details can also raise, which requires nested
exception handling and can be complicated.

412ab26067
2023-11-28 14:05:31 +00:00
TSUYUSATO Kitsune
9365b78d49 [ruby/prism] Fix to parse * as forwarding in foo[*] case
Fix https://github.com/ruby/prism/pull/1924

7cde900065
2023-11-28 13:25:59 +00:00
Kevin Newton
c798943a4a [ruby/prism] Move DATA parsing into its own parse result field
42b60b6e95
2023-11-28 13:25:48 +00:00
Kouhei Yanagita
1a16b6ffc2 Make Range#reverse_each raise TypeError if endless 2023-11-28 15:10:42 +09:00
Kevin Newton
0164da68c1 [ruby/prism] Use un-capitalized error messages
I don't prefer this style, but it appears that a plurality of syntax
error messages between with un-capitalized messages in CRuby, so
we'll go with that for consistency, for now.

b02df68954
2023-11-28 02:53:44 +00:00
Peter Zhu
94015e0dce Guard match from GC when scanning string
We need to guard match from GC because otherwise it could end up being
reclaimed or moved in compaction.
2023-11-27 16:49:52 -05:00
Jemma Issroff
1acea50100 [PRISM] Small fixes to parameters ordering and methods 2023-11-27 16:02:38 -05:00
Jemma Issroff
ba26c6eae0 [PRISM] Compile IndexOperatorWriteNode 2023-11-27 15:14:40 -05:00
Jemma Issroff
ec5eddf695 [PRISM] Compile IndexAndWriteNode 2023-11-27 15:14:40 -05:00