Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10107.
For an object that converts with
to_str,TypeConverter.convertToIntegerparsed the String with the 4-argumentConvertBytes.byteListToInum(runtime, bytes, base, badcheck)and passedexceptionasbadcheck. Withexception: falsethat turned off the check for trailing characters, soInteger(o, exception: false)returned 1 for"1---", 12 for"12abc"and 0 for"0x","0.0"and"". It now callsRubyNumeric.str2inum(runtime, str, base, true, exception), the same call as for a String argument a few lines above, like CRuby'srb_convert_to_integer, which callsrb_str_convert_to_inum(tmp, base, TRUE, raise_exception)in both places (object.c#L3456). Throughstr2inum, ato_strresult in an ASCII-incompatible encoding now also raisesEncoding::CompatibilityError, as it does for a String argument here and in CRuby.This adds "parses the String returned by #to_str" and "swallows an error if the String can't be converted to an Integer" under "when passed exception: false" in
spec/ruby/core/kernel/Integer_spec.rb. The second fails before this change and both pass after it, and pass on CRuby 4.0.9 and 3.4.12. Tested withspec/ruby/core/kernel/Integer_spec.rbandspec/ruby/core/string/to_i_spec.rb(also with-Xjit.threshold=0and-X-C),test/mri/ruby/test_integer.rband the fast RubySpec suite. No new failures.The commit cherry-picks cleanly onto master, and the new examples pass there with the default parser and with
-Xparser.prism.