From 1c29bb76295794fef1b8e2d67ac24db05479e216 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 2 Nov 2023 16:56:07 -0400 Subject: [PATCH] Last typeerror string mismatches for %c fixes --- core/src/main/java/org/jruby/RubyNumeric.java | 3 ++- core/src/main/java/org/jruby/util/Sprintf.java | 4 +--- spec/tags/ruby/core/file/printf_tags.txt | 5 ----- spec/tags/ruby/core/kernel/printf_tags.txt | 2 -- spec/tags/ruby/core/kernel/sprintf_tags.txt | 2 -- spec/tags/ruby/core/string/modulo_tags.txt | 1 - spec/tags/ruby/library/stringio/printf_tags.txt | 1 - 7 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 spec/tags/ruby/core/file/printf_tags.txt delete mode 100644 spec/tags/ruby/core/kernel/printf_tags.txt delete mode 100644 spec/tags/ruby/library/stringio/printf_tags.txt diff --git a/core/src/main/java/org/jruby/RubyNumeric.java b/core/src/main/java/org/jruby/RubyNumeric.java index eaff288007b..3a69997ac81 100644 --- a/core/src/main/java/org/jruby/RubyNumeric.java +++ b/core/src/main/java/org/jruby/RubyNumeric.java @@ -224,7 +224,8 @@ private static long other2long(IRubyObject arg) throws RaiseException { if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } - return arg.convertToInteger().getLongValue(); + + return ((RubyInteger) TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), "to_int")).getLongValue(); } public static long float2long(RubyFloat flt) { diff --git a/core/src/main/java/org/jruby/util/Sprintf.java b/core/src/main/java/org/jruby/util/Sprintf.java index 271f45c8876..aca521e7efc 100644 --- a/core/src/main/java/org/jruby/util/Sprintf.java +++ b/core/src/main/java/org/jruby/util/Sprintf.java @@ -611,9 +611,7 @@ private static void rubySprintfToBuffer(final ByteList buf, final CharSequence c n = StringSupport.codeLength(bl.getEncoding(), c); } else { - // unsigned bits - RubyInteger intValue = (RubyInteger) TypeConverter.convertToType(arg, runtime.getInteger(), "to_int"); - c = (int) intValue.getLongValue() & 0xFFFFFFFF; + c = (int) RubyNumeric.num2long(arg) & 0xFFFFFFFF; try { n = StringSupport.codeLength(encoding, c); } catch (EncodingException e) { diff --git a/spec/tags/ruby/core/file/printf_tags.txt b/spec/tags/ruby/core/file/printf_tags.txt deleted file mode 100644 index 7f57c10f430..00000000000 --- a/spec/tags/ruby/core/file/printf_tags.txt +++ /dev/null @@ -1,5 +0,0 @@ -fails:File#printf integer formats u converts argument as a decimal number -fails:File#printf flags # applies to gG does not remove trailing zeros -fails:File#printf reference by name %{name} style supports flags, width and precision -fails:File#printf other formats c raises TypeError if argument is nil -fails:File#printf other formats c raises TypeError if converting to Integer with to_int returns non-Integer diff --git a/spec/tags/ruby/core/kernel/printf_tags.txt b/spec/tags/ruby/core/kernel/printf_tags.txt deleted file mode 100644 index 1b78d59184a..00000000000 --- a/spec/tags/ruby/core/kernel/printf_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Kernel.printf formatting io is specified other formats c raises TypeError if argument is nil -fails:Kernel.printf formatting io is not specified other formats c raises TypeError if argument is nil diff --git a/spec/tags/ruby/core/kernel/sprintf_tags.txt b/spec/tags/ruby/core/kernel/sprintf_tags.txt index b1e9882e46d..4195a92a340 100644 --- a/spec/tags/ruby/core/kernel/sprintf_tags.txt +++ b/spec/tags/ruby/core/kernel/sprintf_tags.txt @@ -1,5 +1,3 @@ fails(compiler):Kernel#sprintf passes some tests for negative %u -fails:Kernel#sprintf other formats c raises TypeError if argument is nil -fails:Kernel.sprintf other formats c raises TypeError if argument is nil fails:Kernel#sprintf %c raises error when a codepoint isn't representable in an encoding of a format string fails:Kernel.sprintf %c raises error when a codepoint isn't representable in an encoding of a format string diff --git a/spec/tags/ruby/core/string/modulo_tags.txt b/spec/tags/ruby/core/string/modulo_tags.txt index 841a96165f3..ea022223d56 100644 --- a/spec/tags/ruby/core/string/modulo_tags.txt +++ b/spec/tags/ruby/core/string/modulo_tags.txt @@ -1,2 +1 @@ -fails:String#% other formats c raises TypeError if argument is nil fails:String#% %c raises error when a codepoint isn't representable in an encoding of a format string diff --git a/spec/tags/ruby/library/stringio/printf_tags.txt b/spec/tags/ruby/library/stringio/printf_tags.txt deleted file mode 100644 index 346d48ee6e8..00000000000 --- a/spec/tags/ruby/library/stringio/printf_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:StringIO#printf formatting other formats c raises TypeError if argument is nil