質問

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