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