-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:lang:macros
Description
Bug Report
Today I encountered a weird issue that was caused by a symbol array literal. When using the %i[something] format a compile-time error is raised, when using [:something] not.
More specifically, I came across the error when defining a has_many association with a through option in Avram:
has_many tags : Label, through: %i[tag_labelings label]This raised:
11 | has_many tags : Label, through: %i[tag_labelings label]
^
Called macro defined in lib/avram/src/avram/associations/has_many.cr:2:3
2 | macro has_many(type_declaration, through = nil, foreign_key = nil, base_query_class = nil)
Which expanded to:
> 18 |
> 19 | define_has_many_lazy_loading(tags, Label, blip_id, [:tag_labelings, :label] of ::Symbol)
> 20 | define_has_many_base_query(Web::Blip, tags, Label, blip_id, [:tag_labelings, :label] of ::Symbol, Label::BaseQuery)
^
Error: expecting token '->', not ')'
Using an array of symbols works as expected:
has_many tags : Label, through: [:tag_labelings, :label]Crystal version
Crystal 1.19.0 (2026-01-14)
LLVM: 18.1.3
Default target: x86_64-pc-linux-gnu
OS
Ubuntu 24.04.3 LTS
Metadata
Metadata
Assignees
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:lang:macros