繁体   English   中英

为什么 OCaml 代码会出现此编译错误?

[英]Why is there this compilation error for OCaml code?

我目前正在测试 Facebook 的 Infer (open source) v0.17.0 并尝试通过命令使用 bash 文件从源代码构建它

$>./build-infer.sh clang

但是,我在编译它时遇到错误,该错误具体是这样发生的。

[23:35:46][ 98156] Building clang plugin...
[      0s][ 98156] SUCCESS Building clang plugin
[23:35:46][ 98165] Building clang plugin OCaml interface...
[      0s][ 98165] SUCCESS Building clang plugin OCaml interface
[23:35:47][ 98205] Generating source dependencies...
[      0s][ 98205] SUCCESS Generating source dependencies
[23:35:47][ 98298] Building native(opt) Infer...
[*ERROR**][98298] *** ERROR 'Building native(opt) Infer'
[*ERROR**][98298] *** command: ' make INTERACTIVE=1 -C /home/roksui/Dev/dbtest/infer/src infer'
[*ERROR**][98298] *** CWD: '/home/roksui/Dev/dbtest'
[*ERROR**][98298] *** stdout:
[*ERROR**][98298] make[1]: Entering directory '/home/roksui/Dev/dbtest/infer/src'
[*ERROR**][98298] Makefile:122: recipe for target '/home/roksui/Dev/dbtest/infer/bin/infer.exe' failed
[*ERROR**][98298] make[1]: Leaving directory '/home/roksui/Dev/dbtest/infer/src'
[*ERROR**][98298] *** stderr:
[*ERROR**][98298] Entering directory '/home/roksui/Dev/dbtest/infer'
[*ERROR**][98298] File "src/base/Utils.ml", line 322, characters 4-13:
[*ERROR**][98298] 322 |     Unix.dup2 ~src ~dst:Unix.stderr () ;
[*ERROR**][98298]           ^^^^^^^^^
[*ERROR**][98298] Error: This function has type
[*ERROR**][98298]          src:IStdlib.IStd.Unix.File_descr.t ->
[*ERROR**][98298]          dst:IStdlib.IStd.Unix.File_descr.t -> unit
[*ERROR**][98298]        It is applied to too many arguments; maybe you forgot a `;'.
[*ERROR**][98298] make[1]: *** [/home/roksui/Dev/dbtest/infer/bin/infer.exe] Error 1

这似乎是 function Unix.dup2 有太多 arguments 的问题,所以我搜索了 ml 文件,下面是发生错误的代码片段。

let suppress_stderr2 f2 x1 x2 =
  let restore_stderr src =
    Unix.dup2 ~src ~dst:Unix.stderr () ;
    Unix.close src
  in
  let orig_stderr = Unix.dup Unix.stderr in
  Unix.dup2 ~src:(Lazy.force devnull) ~dst:Unix.stderr () ;
  let f () = f2 x1 x2 in
  let finally () = restore_stderr orig_stderr in
  protect ~f ~finally

据我所知,Unix.dup2 function 接受两个 arguments src 和 dst。 但是额外的单位参数()在这里发生了什么?

是否因为我使用了错误版本的 ocaml 编译器而发生此错误? 为什么会出现这个错误? 任何见解将不胜感激。 谢谢你。

Facebook Infer 使用core标准库替换v0.14.x ,它有一个终止unit参数 最新版本不再这样了。 所以问题似乎是你安装了错误的版本。

编辑:实际上,我查看了错误的文档,尽管它托管在简街并在 URL 中多次提到核心,但实际上似乎是 OCaml 标准库 Unix 模块的文档。 Core 中最新版本的Unix.dup2仍然具有可选和终止unit参数。 这可能意味着您根本没有安装Core 但无论哪种方式,您都需要返回 go 并查看我认为的构建和先决条件说明。

当您有一个 function 和可选的 arguments 或仅标记为 arguments 时,通常使用终止unit参数。 如标记的 arguments 可以以任何顺序应用,因此编译器无法知道是否应考虑部分或完全应用没有可选 arguments 的 function 应用程序。 它将假定部分应用,因此在这种情况下可选参数实际上不是可选的。 为了解决这个问题,通常使用未标记的unit参数来告诉编译器 function 应该被认为是完全应用的。

由于某种原因,可选参数与终止unit参数一起从dup2中删除,因为它不再需要。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM