Skip to content

Handle non-string keys returning immediate values via to_s#792

Merged
byroot merged 1 commit into
ruby:masterfrom
byroot:handle-to-s-immediate
Apr 27, 2025
Merged

Handle non-string keys returning immediate values via to_s#792
byroot merged 1 commit into
ruby:masterfrom
byroot:handle-to-s-immediate

Conversation

@byroot
Copy link
Copy Markdown
Member

@byroot byroot commented Apr 27, 2025

We can't directly call RBASIC_CLASS as the return value of to_s may be an immediate.

@byroot byroot force-pushed the handle-to-s-immediate branch from 365c4b9 to b2cd83f Compare April 27, 2025 09:58
We can't directly call `RBASIC_CLASS` as the return value of
`to_s` may be an immediate.
@byroot byroot force-pushed the handle-to-s-immediate branch from b2cd83f to 12dc394 Compare April 27, 2025 10:13
@byroot byroot merged commit 05cc998 into ruby:master Apr 27, 2025
33 checks passed
{
VALUE key_to_s = rb_funcall(key, i_to_s, 0);

if (RB_UNLIKELY(rb_type(key_to_s) != T_STRING)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it doesn't handle T_STRING explicitly currently, so I guess it's the same, but maybe in the future it might?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unlucky path, so I don't think it matter too much, but it's nicer to read, so I changed it.

@byroot byroot deleted the handle-to-s-immediate branch April 27, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants