Attributes - cyxigo/wi GitHub Wiki
Introduction
Attributes are metadata for the Wi compiler – an additional information that can alter how it behaves when dealing with certain variables. Syntax is simple:
name @attr := value;
Also can be used with function parameters:
f := |x @attr| => {
};
Now let's go over each one!
@const
Marks variable as read-only – any attempt to reassign it will cause a compile error
a @const := 10;
a = 20;
Will result in:
compile error: cannot reassign variable a
|
2 | a = 20;
| ^
--> file.wi:2:3
@unused
Suppress unused local (or a function parameter) warning
f := |x| => {
};
compile warning: local variable x was defined but not used
|
1 | f := |x| => {
| ^
--> file.wi:1:7
With @unused:
f := |x @unused| => {
};
(No warnings)
@deprecated
Mark variable as deprecated and warn on every use
x @deprecated := "hi";
std::puts(x);
compile warning: use of deprecated variable x
|
2 | std::puts(x);
| ^
--> file.wi:2:11
hi
Combining
Attributes can be combined:
a @const @deprecated := 10;
Unknown attributes
An unknown attribute is a compile error:
compile error: unknown attribute hello
|
1 | a @hello := 0;
| ^^^^^
--> file.wi:1:4
Next: The End