Project

General

Profile

Actions

Bug #22407

open

IO::Buffer#set_value does not call to_int for 128-bit values

Bug #22407: IO::Buffer#set_value does not call to_int for 128-bit values

Added by hanazuki (Kasumi Hanazuki) about 3 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-10-05T15:26:55Z master 2c1e694a53) +PRISM [x86_64-linux]
[ruby-core:126927]

Description

IO::Buffer gained support for reading and writing 128-bit integers (:u128, :U128, :s128, and :S128) in Ruby 4.0 (a7dc53b91c8475323b34d5a332fdb25d190e277d).
Unlike the other smaller integer types, IO::Buffer#set_value does not call to_int on non-Integer values for the 128-bit types. Same for #set_values.

IntegerLike = Data.define(:value) do
  def to_int = value
end

buf = IO::Buffer.new(16)
buf.set_value(:u64, 0, IntegerLike.new(42))
buf.set_value(:u128, 0, IntegerLike.new(42))  # => not an integer (TypeError)

Hence the 128-bit integer types do not satisfy this statement in the method's documentation:

Note that if the type is integer and value is Float, the implicit truncation is performed

No data to display

Actions

Also available in: PDF Atom