summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.c8
-rw-r--r--lib/prism/translation/parser/compiler.rb23
-rw-r--r--test/prism/fixtures/escaped_newline_with_trailing_content.txt2
-rw-r--r--test/prism/fixtures/unary_method_calls.txt6
-rw-r--r--test/ruby/test_string.rb3
-rw-r--r--thread_sync.rb38
-rw-r--r--zjit.rb2
7 files changed, 34 insertions, 48 deletions
diff --git a/file.c b/file.c
index ae741ce567..17a38637c6 100644
--- a/file.c
+++ b/file.c
@@ -5520,11 +5520,11 @@ rb_file_join_fastpath(long argc, VALUE *args)
if (tmp_len > 0 && isdirsep(tmp_s[0])) {
// right side has a leading separator, remove left side separators.
- long trailing_seps = 0;
- while (isdirsep(name[len - trailing_seps - 1])) {
- trailing_seps++;
+ long chomp = len;
+ while (chomp > 0 && isdirsep(name[chomp - 1])) {
+ --chomp;
}
- rb_str_set_len(result, len - trailing_seps);
+ rb_str_set_len(result, chomp);
}
else if (len < 1 || !isdirsep(name[len - 1])) {
// neither side have a separator, append one;
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index d4e94ae5e0..d11db12ae6 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -297,11 +297,6 @@ module Prism
if node.call_operator_loc.nil?
case name
- when :-@
- case (receiver = node.receiver).type
- when :integer_node, :float_node, :rational_node, :imaginary_node
- return visit(numeric_negate(node.message_loc, receiver))
- end
when :!
return visit_block(builder.not_op(token(node.message_loc), token(node.opening_loc), visit(node.receiver), token(node.closing_loc)), block)
when :=~
@@ -1973,22 +1968,6 @@ module Prism
elements
end
- # Negate the value of a numeric node. This is a special case where you
- # have a negative sign on one line and then a number on the next line.
- # In normal Ruby, this will always be a method call. The parser gem,
- # however, marks this as a numeric literal. We have to massage the tree
- # here to get it into the correct form.
- def numeric_negate(message_loc, receiver)
- case receiver.type
- when :integer_node, :float_node
- receiver.copy(value: -receiver.value, location: message_loc.join(receiver.location))
- when :rational_node
- receiver.copy(numerator: -receiver.numerator, location: message_loc.join(receiver.location))
- when :imaginary_node
- receiver.copy(numeric: numeric_negate(message_loc, receiver.numeric), location: message_loc.join(receiver.location))
- end
- end
-
# Blocks can have a special set of parameters that automatically expand
# when given arrays if they have a single required parameter and no
# other parameters.
@@ -2199,7 +2178,7 @@ module Prism
else
lines.sum do |line|
count = line.scan(/(\\*)n/).count { |(backslashes)| backslashes&.length&.odd? }
- count -= 1 if !line.end_with?("\n") && count > 0
+ count -= 1 if line.match?(/(?:\A|[^\\])(?:\\\\)*\\n\z/) && count > 0
count
end
end
diff --git a/test/prism/fixtures/escaped_newline_with_trailing_content.txt b/test/prism/fixtures/escaped_newline_with_trailing_content.txt
new file mode 100644
index 0000000000..fe947a3f10
--- /dev/null
+++ b/test/prism/fixtures/escaped_newline_with_trailing_content.txt
@@ -0,0 +1,2 @@
+"A
+B\nCC"
diff --git a/test/prism/fixtures/unary_method_calls.txt b/test/prism/fixtures/unary_method_calls.txt
index dda85e4bdb..a8327d23cc 100644
--- a/test/prism/fixtures/unary_method_calls.txt
+++ b/test/prism/fixtures/unary_method_calls.txt
@@ -1,2 +1,8 @@
42.~@
42.!@
+
+-
+42
+
++
+42
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 67a19e1ae0..aedfc93e5d 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -851,7 +851,6 @@ CODE
assert_equal(S("\u{AB}"), S('"\\u00AB"').undump)
assert_equal(S("\u{ABC}"), S('"\\u0ABC"').undump)
assert_equal(S("\uABCD"), S('"\\uABCD"').undump)
- assert_equal(S("\uABCD"), S('"\\uABCD"').undump)
assert_equal(S("\u{ABCDE}"), S('"\\u{ABCDE}"').undump)
assert_equal(S("\u{10ABCD}"), S('"\\u{10ABCD}"').undump)
assert_equal(S("\u{ABCDE 10ABCD}"), S('"\\u{ABCDE 10ABCD}"').undump)
@@ -2629,7 +2628,7 @@ CODE
end
def test_upcase
- assert_equal(S("HELLO"), S("hello").upcase)
+ assert_equal(S("HELLO"), S("helLO").upcase)
assert_equal(S("HELLO"), S("hello").upcase)
assert_equal(S("HELLO"), S("HELLO").upcase)
assert_equal(S("ABC HELLO 123"), S("abc HELLO 123").upcase)
diff --git a/thread_sync.rb b/thread_sync.rb
index c9d37772d7..18c7cc7adc 100644
--- a/thread_sync.rb
+++ b/thread_sync.rb
@@ -11,23 +11,23 @@ class Thread
#
# Example:
#
- # queue = Thread::Queue.new
+ # queue = Thread::Queue.new
#
- # producer = Thread.new do
- # 5.times do |i|
- # sleep rand(i) # simulate expense
- # queue << i
- # puts "#{i} produced"
- # end
- # end
+ # producer = Thread.new do
+ # 5.times do |i|
+ # sleep rand(i) # simulate expense
+ # queue << i
+ # puts "#{i} produced"
+ # end
+ # end
#
- # consumer = Thread.new do
- # 5.times do |i|
- # value = queue.pop
- # sleep rand(i/2) # simulate expense
- # puts "consumed #{value}"
- # end
- # end
+ # consumer = Thread.new do
+ # 5.times do |i|
+ # value = queue.pop
+ # sleep rand(i/2) # simulate expense
+ # puts "consumed #{value}"
+ # end
+ # end
#
# consumer.join
class Queue
@@ -42,13 +42,13 @@ class Thread
#
# Example:
#
- # q = Thread::Queue.new
+ # q = Thread::Queue.new
# #=> #<Thread::Queue:0x00007ff7501110d0>
# q.empty?
# #=> true
#
- # q = Thread::Queue.new([1, 2, 3])
- # #=> #<Thread::Queue:0x00007ff7500ec500>
+ # q = Thread::Queue.new([1, 2, 3])
+ # #=> #<Thread::Queue:0x00007ff7500ec500>
# q.empty?
# #=> false
# q.pop
@@ -113,7 +113,7 @@ class Thread
#
# Example:
#
- # q = Thread::Queue.new
+ # q = Thread::Queue.new
# Thread.new{
# while e = q.deq # wait for nil to break loop
# # ...
diff --git a/zjit.rb b/zjit.rb
index cd4f9188b2..9c7309d67b 100644
--- a/zjit.rb
+++ b/zjit.rb
@@ -7,7 +7,7 @@
# This module may not exist if ZJIT does not support the particular platform
# for which CRuby is built.
module RubyVM::ZJIT
- # Blocks that are called when YJIT is enabled
+ # Blocks that are called when ZJIT is enabled
@jit_hooks = []
# Avoid calling a Ruby method here to avoid interfering with compilation tests
if Primitive.rb_zjit_get_stats_file_path_p