Bug Report
MacroExpression output uses to_s(emit_doc: true) (macros/interpreter.cr:129), and ToSVisitor#visit_any writes a node's doc as # ... lines in front of the node, even when {{ }} is in the middle of a line. The comment then comments out the rest of that line, so the expansion means something different in doc mode.
def foo(a, b = 0)
puts "foo(#{a}, #{b})"
end
macro m(&block)
foo {{ block.body }}, 2
{% debug %}
end
m do
# doc
y = 1
end
crystal run expands to foo y = 1, 2 and prints foo(1, 2).
crystal docs expands to:
foo # doc
y = 1, 2
This fails with Error: Multiple assignment count mismatch. If the result had still parsed, crystal docs would silently document a different program.
Possible fix: only emit docs when the node starts a line in the output, or put the doc somewhere else instead of writing it as a comment.
Tested with Crystal 1.22.3.
Add a :+1: reaction to issues you find important.