natalie icon indicating copy to clipboard operation
natalie copied to clipboard

Keyword arg with default cannot reference a previous positional arg with default

Open seven1m opened this issue 9 months ago • 0 comments

Because of the way we build our argument instructions, the following code produces a compilation error:

https://github.com/rack/rack/blob/main/lib/rack/multipart/uploaded_file.rb#L16-L17

Basically, you cannot have this:

def foo(a = 1, b: a)
end

I have half a mind to rewrite our Args class. When I wrote that, I didn't have good information from the parser, and I thought the only way to consume the arguments properly was to build a sort of state machine.

Now Prism gives us much better information, i.e.:

node.requireds
node.rest
node.optionals
node.posts
node.keywords
node.keyword_rest
node.block

I think using this information (vs what we do now, which is to basically smoosh them together) will greatly simplify that class and allow us to consume the arguments in order, thus fixing this bug. 🤞

seven1m avatar May 31 '24 22:05 seven1m