そこで、ただコンパイルの前にtrue/falseが判定されるだけのマクロを書いて対処しました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Hoge do | |
@flag false | |
defmacro ifa(a, exp) do | |
if (Macro.expand_once(a, __CALLER__)), do: exp | |
end | |
def main do | |
if (@flag), do: IO.puts 123 | |
ifa (@flag), do: IO.puts 456 | |
end | |
end |
% mix dialyzer Starting Dialyzer dialyzer --no_check_plt --plt C:\Users\moccos/.dialyxir_core_18_1.2.3.plt (オプション略) Proceeding with analysis... hoge.ex:8: The pattern 'false' can never match the type 'true' done in 0m1.31s done (warnings were emitted)
# 最初に書いたバージョンに間違いがあったので、2016/03/28に修正しました。
# Elixir1.3系で動かなかったので2016/06/24に再度修正