erlang - 如何让 Dialyzer 接受对故意抛出的函数的调用?
问题描述
我有一个函数,当它的第一个参数是 atom 时,它会故意抛出throw
。
此代码的简化版本是:
-module(sample).
-export([main/1, throw_or_ok/1]).
main(_Args) ->
throw_or_ok(throw).
throw_or_ok(Action) ->
case Action of
throw -> throw("throwing");
ok -> ok
end.
调用时出现透析器错误throw_or_ok
:
sample.erl:7: The call sample:throw_or_ok
('throw') will never return since it differs in the 1st argument from the success typing arguments:
('ok')
添加规格没有帮助,错误消息是相同的:
-module(sample).
-export([main/1, throw_or_ok/1]).
-spec main(_) -> no_return().
main(_Args) ->
throw_or_ok(throw).
-spec throw_or_ok(throw) -> no_return(); (ok) -> ok.
throw_or_ok(Action) ->
case Action of
throw -> throw("throwing");
ok -> ok
end.
我怎样才能让 Dialyzer 接受throw_or_ok/1
保证会抛出的调用?
解决方案
不幸的是,目前没有明确的方法可以通过规范将此标记为 Dialyzer 可接受的。
但是,也许您可以使用忽略警告注释。
推荐阅读
- c++ - 不能包含
- ethereum - Solidity 事件未从 Web3.js 显示
- javascript - 由于树使用的 SQL 查询中的变量,JS 树无法获得正确的数据
- python - 如何使用 pgerror 集引发 psycopg2 ProgrammingError?
- java - 通过在线每月订阅限制我的 java 应用程序
- r - 获取具有缺失 (NA) 值的列的平均值
- python - 如何每分钟通过 API 下载一个 json 文件而不会被 asyncio 停止?
- r - 控制 n 个重叠区域的 alpha 混合/不透明度
- r - 在 R 中建模响应行为
- excel - 如何修复 vba for excel 中的运行时错误“430”和其他自动化错误