Elixir compiler: Having a @some_name in a @moduledoc gives a warning

Havin this @moduledoc:

@moduledoc """
  Weekly schedule - extended version for admins, managers and users.

  ## Examples
  <div class={"flex #{if @is_home, do: ~c"home"}"}> for inline conditionals (for example for class names) inside elixir templates, maybe this will be helpful to someone

the compiler gives following warning:

warning: undefined module attribute @is_home, please remove access to @is_home or explicitly set it before access

How comes the html example is considered (somehow) as code?
Is it working as designed and I’m doing something wrong??

It’s because of the #{} in the code, it starts interpolating in the string (delimited with """).

Try something like

@moduledoc ~S"""

That should prevent interpolation inside the string (~S is a sigil for string without interpolation).


@Nicd Thank you!

Though I did not expect to see any kind of interpolation happening in a @moduledoc string

""" is simply a plain ol’ heredoc delimiter which allows interpolation. It would be far more surprising to give """ special meaning in a core language feature. It doesn’t even have to be a heredoc, just anything that returns a string (or false or a keyword list but that is tangential to this point). This has utility as it means we can dynamically generate all or parts of it. There is a good example here.


Well, I thought it is a core language feature…
Thanks for clarifying

It is, that’s what I’m saying. Heredocs allow interpolation unless you use ~S as @Nicd pointed out. I’m saying it would be weird for the core language feature of @moduledoc to treat them differently, is all.


not really… """ is a multiline string, it isn’t suppose to denote documentation neither to only be used in documentation. I guess using the term heredoc in this case is what is making your explanation confusing. :thinking:

I use the terms “heredoc” and “multi-line string” interchangeably, as do parts of the Elixir documentation. The term “heredoc” has nothing to do with documentation and I certainly wasn’t trying to imply that it did by calling it that. In fact I was trying to imply the exact opposite but clearly failed.


i know the term heredoc from other langs but i thought elixir always used multiline string for that purpouse :thinking:
like here

I probably misremembered about how much I’d seen it in the docs. I only see it in a couple of places in hexdocs and elixir-lang.org has a line:

Sigils also support heredocs, that is, three double-quotes or single-quotes as separators:

In any event, I still call 'em heredocs but I guess I should stop that when talking about them 'round here though this is the first time this has happen :sweat_smile: My point was trying to convey to OP to help with their confusion was that """ isn’t special to @moduledoc or any other module attributes.


TIL i can do something like that

another_atom third_atom
1 Like