Erlang / Erlang Advanced Interview questions
Why doesn't Dialyzer catch every type error the way a traditional type checker would?
Success typing is intentionally conservative: it only reports a call site when it can prove the function can never succeed with those argument types, based on inferring what the function's body could actually produce or accept. If a function's implementation is loose enough that a call is merely suspicious rather than provably impossible, Dialyzer stays silent about it.
maybe_int(X) when is_integer(X) -> X; maybe_int(X) -> X. %% falls through for ANY other type, so nothing is provably wrong bad() -> maybe_int("oops"). %% Dialyzer says nothing here
Because the second clause accepts any value unconditionally, Dialyzer can't prove the call fails, even
though it's clearly not what the author intended. This is the direct tradeoff for success typing's low
false-positive rate: it trades completeness (catching every questionable call) for
soundness of what it does report (never crying wolf on code that actually works). Writing precise
-spec annotations and using strict guards narrows this gap, but Dialyzer will never behave like a
type checker that rejects unproven code by default.
More Related questions...