You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you parse a string like foo = bar { |x| x + 1 }, then traverse it down to the block node ({ |x| x + 1 }), trying to format that node throws an error. Here's a repro case:
require'syntax_tree'# Create a node visitor that walks the syntax tree looking for blocks.classBlockFinder < SyntaxTree::Visitorattr_reader:first_blockvisit_methoddefvisit_do_block(node)puts"found a brace block node!"@first_block ||= node# Don't traverse furtherendvisit_methoddefvisit_brace_block(node)puts"found a brace block node!"@first_block ||= node# Don't traverse furtherendendinput_string="foo = bar() { |x| x + 1}"root=SyntaxTree.parse(input_string)# use that visitor to find the first, outermost blockvisitor=BlockFinder.newvisitor.visit(root)block_node=visitor.first_blockformatter=SyntaxTree::Formatter.new(input_string,[],80)# !!! This throws an error:# /Users/kevin/.rvm/gems/ruby-3.0.0/gems/syntax_tree-3.6.0/lib/syntax_tree/node.rb:1990:in `forced_do_end_bounds?': undefined method `call' for nil:NilClassformatter.format(block_node)# But if I comment that line out and then fake that this block node is nested# within a parent node, it works:formatter.instance_variable_set(:@stack,[proc{SyntaxTree::Program.new(statements: [],location: nil)}])formatter.format(block_node)formatter.flushoutput_string=formatter.output.joinputsoutput_string# Prints { |x| x + 1 }
The issue seems to be that forced_do_end_bounds in BlockFormatter inspects the parent node and doesn't handle when it doesn't exist.
PS: thanks for the great tool and, honestly, the very readable source!
The text was updated successfully, but these errors were encountered:
If you parse a string like
foo = bar { |x| x + 1 }
, then traverse it down to the block node ({ |x| x + 1 }
), trying to format that node throws an error. Here's a repro case:The issue seems to be that
forced_do_end_bounds
inBlockFormatter
inspects the parent node and doesn't handle when it doesn't exist.PS: thanks for the great tool and, honestly, the very readable source!
The text was updated successfully, but these errors were encountered: