The error message is odded when try to assign a value to const in macro

Yes, i guess i know i should’t do like this, because, when macro is expanding, all const should be already defined, right?

but, still, following code error message is odded.

{% ROOT="/home/zw963" %}
In 1.cr:1:1

 1 | {% ROOT="/home/zw963" %}
     ^
Error: expanding macro


In 1.cr:1:4

 1 | {% ROOT="/home/zw963" %}
        ^
Error: can only assign to variables, not Path

What is the Path?

You’re getting into the macro API. By Path, it means Crystal::Macros::Path - Crystal 1.4.1, which basically is a type that represents a const/type; i.e. the FQN of it.

I think the gist of this error is that you can’t redefine the value of a const; you can only mutate it. Maybe this error could be updated to make that more clear :person_shrugging:.

3 Likes