Skip to content

Commit 4b844f7

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Ensure backwards compatibility with the custom parser builder
Temoprary backwards-compat code so that current users don't break. Eventually the Translation::Parser initializer should asser that the correct class is passed in. ruby/prism@66b0162b35
1 parent 7c88cbb commit 4b844f7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,17 @@ def visit_it_local_variable_read_node(node)
11381138
# -> { it }
11391139
# ^^^^^^^^^
11401140
def visit_it_parameters_node(node)
1141-
builder.itarg
1141+
# FIXME: The builder _should_ always be a subclass of the prism builder.
1142+
# Currently RuboCop passes in its own builder that always inherits from the
1143+
# parser builder (which is lacking the `itarg` method). Once rubocop-ast
1144+
# opts in to use the custom prism builder a warning can be emitted when
1145+
# it is not the expected class, and eventually raise.
1146+
# https://github.com/rubocop/rubocop-ast/pull/354
1147+
if builder.is_a?(Translation::Parser::Builder)
1148+
builder.itarg
1149+
else
1150+
builder.args(nil, [], nil, false)
1151+
end
11421152
end
11431153

11441154
# foo(bar: baz)

0 commit comments

Comments
 (0)