More robust trailing expressions newline implementation#15614
Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom Apr 29, 2025
Merged
More robust trailing expressions newline implementation#15614straight-shoota merged 4 commits intocrystal-lang:masterfrom
straight-shoota merged 4 commits intocrystal-lang:masterfrom
Conversation
straight-shoota
approved these changes
Apr 25, 2025
Member
|
Why tag this as |
Member
Author
|
My thinking was that stringification is related to macros so this Yea, if you have: macro finished
{% verbatim do %}
{%
to_process = [] of Nil
to_process.each do
b = 2
a = 1
end
raise "oh noes"
%}
{% end %}
endWithout this PR: $ crystal run --error-trace test.cr
In test.cr:1:1
1 | macro finished
^
Error: expanding macro
...
> 1 |
> 2 | {%
> 3 | to_process = [] of Nil
> 4 |
> 5 | to_process.each do
> 6 | b = 2
> 7 | a = 1 end
> 8 |
> 9 | raise("oh noes")
> 10 | %}
> 11 |
Error: oh noesWith this PR: $ ccrystal run --error-trace test.cr
Using compiled compiler at /home/george/dev/git/crystal/.build/crystal
In test.cr:1:1
1 | macro finished
^
Error: expanding macro
...
> 1 |
> 2 | {%
> 3 | to_process = [] of Nil
> 4 |
> 5 | to_process.each do
> 6 | b = 2
> 7 | a = 1
> 8 | end
> 9 |
> 10 | raise("oh noes")
> 11 | %}
> 12 |
Error: oh noes |
Member
|
No, this is really just compiler behaviour. Not a language feature change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #15305 to handle another edge case I noticed.
Before this PR if you had a macro expression whose body is an Expressions node, and the last node of those expressions was a Block or If statement, the
endkeyword would be on the wrong line. For example{% to_process = [] of Nil to_process.each do b = 2 a = 1 end %}would be stringified as:
{% to_process = [] of Nil to_process.each do b = 2 a = 1 end %}This PR resolves this and adds more test coverage on similar cases.
Supersedes #15613