Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top