Skip to content

Fix numbered parameters when used as a singleton#6415

Merged
matz merged 1 commit intomruby:masterfrom
hoshiumiarata:fix_numbered_parameters_in_singleton
Nov 15, 2024
Merged

Fix numbered parameters when used as a singleton#6415
matz merged 1 commit intomruby:masterfrom
hoshiumiarata:fix_numbered_parameters_in_singleton

Conversation

@hoshiumiarata
Copy link
Copy Markdown
Contributor

It seems that using a numbered parameter as a singleton is generating an incorrect AST, so code like this is not working:

o = Object.new
o.tap { def _1.a(b) = "a#{b}" }

=> undefined method '_1' (NoMethodError)

It generates the following AST:

00002               NODE_SDEF:
00002                 NODE_FCALL:
00002                   method='_1' (31195136)
00002                 :a
00002                   mandatory args:
00002                     NODE_ARG b

I tried to fix it, so it generates the following AST now:

00002               NODE_SDEF:
00002                 NODE_NVAR 1
00002                 :a
00002                   mandatory args:
00002                     NODE_ARG b

I'm not sure if this is the best way to fix it, so it's okay to fix it in another way if it's better.

@hoshiumiarata hoshiumiarata requested a review from matz as a code owner November 12, 2024 15:37
@matz matz merged commit e0d9bce into mruby:master Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants