我正在使用透析器修复Erlang代码中的错误。
io:format(IoDevice, "[]");
这一行会产生以下错误:
The call io:format(IoDevice::pid(),[91 | 93,...])
will never return since the success typing is
(atom() | binary() | string(),[any()]) -> 'ok'
and the contract is (Format,Data) -> 'ok'
when Format :: format(), Data :: [term()]
我不明白问题出在哪里,有人能解释一下吗?
谢谢
发布于 2018-07-02 14:37:40
我建议阅读io手册页。它的用法很简单:
1> io:format("hello ~p~n", [world]). % ~n means newline
hello world
ok
2> io:format("hello ~p~n", [<<"world">>]).
hello <<"world">>
ok
3> io:format("hello ~s~n", [<<"world">>]).
hello world
ok
在上面,透析器告诉你,io:format/2
(format/2
指的是接受2个参数的函数format
)接受atom()
、string()
或binary()
作为第一个参数,以零或多个元素作为第二个参数的列表。根据您的代码,透析器检测到IoDevice
是Erlang pid()
,而不是string()
或binary()
。
https://stackoverflow.com/questions/51137980
复制相似问题