2

我正在使用 Dialyzer 修复 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()]

我无法理解问题是什么,谁能解释一下?

谢谢

4

1 回答 1

6

我建议阅读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/2format/2表示format接受 2 个参数的函数)接受一个atom()string()binary()作为第一个参数,以及一个具有零个或多个元素的列表作为第二个参数。根据您的代码,dialyzer 检测到IoDevice是 Erlangpid()而不是string()or binary()

于 2018-07-02T14:37:40.733 回答