I just had the idea that I would create a struct with some fields in uppercase, and I ran in to a lot of seemingly weird behaviour.
Given this code:
defmodule Lower do
defstruct lower: "lower"
end
defmodule Upper do
defstruct UPPER: "UPPER"
end
When I try these out in IEx, I can instantiate them just fine, and I can type lower.
and hit the tab-key, and it prints the fields, but I can’t seem to tab-complete the UPPER
field on an %Upper{}
struct, and if I manually type it out, I get an error message:
iex(38)> lower = %Lower{}
%Lower{lower: "lower"}
iex(39)> lower.
__struct__ lower
iex(39)> lower.lower
"lower"
iex(40)> upper = %Upper{}
%Upper{UPPER: "UPPER"}
iex(41)> upper.
UPPER __struct__
iex(41)> upper.UPPER
** (CompileError) iex:41: invalid alias: "upper.UPPER". If you wanted to define an alias, an alias must expand to an atom at compile time but it did not, you may use Module.concat/2 to build it at runtime. If instead you wanted to invoke a function or access a field, wrap the function or field name in double quotes
Does anyone know if this is intended, and if so, where I can read up on why this happens?