如何从 Dialyzer 修复 "will never return since the success typing is [...] and the contract is.."?
How do I fix a "will never return since the success typing is [...] and the contract is.." from Dialyzer?
我正在使用 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()]
我无法理解问题所在,谁能解释一下?
谢谢
我推荐阅读io manual page。它的用法很简单:
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()
.
我正在使用 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()]
我无法理解问题所在,谁能解释一下?
谢谢
我推荐阅读io manual page。它的用法很简单:
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()
.