当我有文件foo.ml
时:
let foo = [];;
let bar =
match [] with
| [] -> [];;
我尝试将第4行的缺失匹配案例标记为错误:
#warn_error "+8";;
#use "foo.ml";;
我在#use
的输出结束前得到了对第1行的虚假行引用:
val foo : 'a list = []
File "foo.ml", line 4, characters 2-26:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
_::_
File "foo.ml", line 1:
Error: Some fatal warnings were triggered (1 occurrences)
这当然不是一个真正的问题,但我仍然发现虚假的线条引用令人恼火。有没有办法说服OCaml不要在输出中打印那条不相关的File "foo.ml", line 1:
行?
答案 0 :(得分:3)
不幸的是,这就是编译器的工作原理。您可以在parsing/location.ml中找到此功能的源代码。实施致命警告的方法是通过构建相对于文件本身的错误消息:
| Warnings.Errors n ->
Some
(errorf ~loc:(in_file !input_name)
"Some fatal warnings were triggered (%d occurrences)" n)
in_file
功能是您看到"第1行和第34行的原因:
let in_file name =
let loc = {
pos_fname = name;
pos_lnum = 1;
pos_bol = 0;
pos_cnum = -1;
} in
{ loc_start = loc; loc_end = loc; loc_ghost = true }
此数据类型缺少表示文件名但没有行号的位置的方法。
答案 1 :(得分:0)
我不认为它是虚假的。它指的是整个文件的事实。他们必须选择一些代表整个文件的行。