문제

if I have multiple clauses of a function, with their type spec:
i) @spec foo(number)::string
ii) @spec foo(string):: number
iii) @spec foo(tuple):: string

When I call foo with a tuple (in a unit test), would it first try to pattern match with clauses i) and ii), and then iii) or would it straight away check iii) since i) and ii) clearly fail static analysis.

도움이 되었습니까?

해결책

Function patterns are matched in source order, so it would start with 1, then 2, then 3. Dialyzer is smart enough to know that foo({1, 2}) matches one of the valid type specs though, and would not fail.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top