Using && inside macro produces warning: this check/guard will always yield the same result

Would like to know why am I getting a warning: this check/guard will always yield the same result
when trying to use “&&” inside macro and how to solve it.

For example my macro is:

defmacro auth(left, right) do
    quote do
      unquote(left) && unquote(right)
    end
  end

which is being used as:

def testing() do
    auth(true, false)
  end

This translates to true && false which is always false. Can you elaborate onw hat about this functionality couldn’t be done with a function?

1 Like

The reason is that after the macro expansion you end up with code that looks like this:

def testing do
  true && false
end

Which the compiler knows will always produce the same result.

@kip @benwilson512

Sorry guys I think I misdiagnosed the problem. I am using GitHub - arjan/decorator: Function decorators for Elixir and I have set @decorate_all my_decorator(:some_arg)
The problem could be from the decorator. The warning is gone when I removed it.

cc: @arjan

I think this might be related to this issue: [Question] What to do about used/unused variable warnings? · Issue #31 · arjan/decorator · GitHub, which is something I have been looking into a long time ago but without a current solution unfortunately…

1 Like