diff --git a/io_buffer.c b/io_buffer.c index 9599cc6a28c0e7..e7a03fcb786b14 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -1684,11 +1684,14 @@ io_buffer_validate_range(struct rb_io_buffer *buffer, size_t offset, size_t leng } /* - * call-seq: hexdump([offset, [length, [width]]]) -> string + * call-seq: hexdump([offset, [length, [width]]]) -> string or nil * * Returns a human-readable string representation of the buffer. The exact * format is subject to change. * + * Returns +nil+ if the buffer does not reference any memory, that is, if + * #null? returns +true+ (for example after #free or #transfer). + * * buffer = IO::Buffer.for("Hello World") * puts buffer.hexdump * # 0x00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello World @@ -1961,10 +1964,18 @@ io_buffer_resize(VALUE self, VALUE size) } /* - * call-seq: <=>(other) -> true or false + * call-seq: <=>(other) -> integer + * + * Returns a negative integer, zero, or a positive integer if the receiver is + * less than, equal to, or greater than +other+, respectively. + * + * Buffers are compared by size first, and if the sizes are equal, by the exact + * contents of the memory they are referencing using +memcmp+. Only the sign of + * the returned integer is meaningful; the result of +memcmp+ is returned as is. * - * Buffers are compared by size and exact contents of the memory they are - * referencing using +memcmp+. + * IO::Buffer.for("abc") <=> IO::Buffer.for("abc") # => 0 + * IO::Buffer.for("abc") <=> IO::Buffer.for("ab") # => 1 + * IO::Buffer.for("abc") <=> IO::Buffer.for("abd") # => -1 */ static VALUE rb_io_buffer_compare(VALUE self, VALUE other) @@ -3540,7 +3551,7 @@ memory_and(unsigned char * restrict output, const unsigned char * restrict base, * * IO::Buffer.for("1234567890") & IO::Buffer.for("\xFF\x00\x00\xFF") * # => - * # # + * # # * # 0x00000000 31 00 00 34 35 00 00 38 39 00 1..45..89. */ static VALUE diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 8e17b5b61e951f..1ef30dab1beac8 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -165,7 +165,14 @@ def visit_assoc_node(node) else parts = if key.is_a?(SymbolNode) - [builder.string_internal([key.unescaped, srange(key.value_loc)])] + value_loc = key.value_loc + if value_loc.nil? + [] + elsif value_loc.slice.include?("\n") + string_nodes_from_line_continuations(key.unescaped, value_loc.slice, value_loc.start_offset, key.opening) + else + [builder.string_internal([key.unescaped, srange(value_loc)])] + end else visit_all(key.parts) end diff --git a/prism/prism.c b/prism/prism.c index 3b6b6f64fb9f15..1f62ea5addc9fd 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -22403,11 +22403,7 @@ parse_expression_terminator(pm_parser_t *parser, pm_node_t *node) { // A block call (command with do-block, or any call chained // from one) can only be followed by call chaining (., ::, // &.), composition (and/or), and modifier operators. - if (pm_block_call_p(node)) { - return left > PM_BINDING_POWER_COMPOSITION && left < PM_BINDING_POWER_CALL; - } - - return false; + return left > PM_BINDING_POWER_COMPOSITION && left < PM_BINDING_POWER_CALL && pm_block_call_p(node); } case PM_SUPER_NODE: case PM_YIELD_NODE: @@ -22419,10 +22415,7 @@ parse_expression_terminator(pm_parser_t *parser, pm_node_t *node) { /* A super carrying a do-block is a block call, so it may also be * followed by call chaining (`.`, `::`, `&.`). */ - if (pm_block_call_p(node)) { - return left > PM_BINDING_POWER_COMPOSITION && left < PM_BINDING_POWER_CALL; - } - return false; + return left > PM_BINDING_POWER_COMPOSITION && left < PM_BINDING_POWER_CALL && pm_block_call_p(node); case PM_DEF_NODE: // An endless method whose body is a command-style call (e.g., // `def f = foo bar`) is a command assignment and can only be diff --git a/test/prism/fixtures/hashes.txt b/test/prism/fixtures/hashes.txt index 0afb8db496d1f2..c6abbf086c0d08 100644 --- a/test/prism/fixtures/hashes.txt +++ b/test/prism/fixtures/hashes.txt @@ -26,3 +26,9 @@ tap do end { a: -1 } + +{ "": nil} + +{ "foo +bar": nil} +