Skip to content

Fix nested sigil delimiter parsing inside macros#16266

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/macro-sigil-nest
Oct 26, 2025
Merged

Fix nested sigil delimiter parsing inside macros#16266
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/macro-sigil-nest

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Oct 24, 2025

Sigils record their opening and closing delimiters so that the delimiters themselves could be nested in the sigil body. Sigils inside macros are no exception:

macro foo
  %w(four (five) six) # okay, second element is "(five)"
end

However, it turns out the lexer uses the sigil name itself as the start delimiter, instead of its next character. This leads to some rather strange behavior:

# okay, second `(` does not start a nested region
# errors on macro expansion instead
macro foo
  %w(four (five) %w(six)
end
# error, `w` inside `two` starts a nested region but only one `)` found
macro foo
  %w(one two three)
end
# okay, every `w` is "matched" by a closing `)`
# errors on expansion
macro foo
  %w(www))))
end

This PR ensures the correct start delimiters are used.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser topic:lang:macros labels Oct 24, 2025
@straight-shoota straight-shoota merged commit a9726d3 into crystal-lang:master Oct 26, 2025
42 checks passed
@HertzDevil HertzDevil deleted the bug/macro-sigil-nest branch October 26, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser topic:lang:macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants