Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source highlighting for contextual errors broken by line directives #8889

trefis opened this issue Aug 23, 2019 · 1 comment


Copy link

commented Aug 23, 2019

You can reproduce by applying this patch to trunk:

diff --git a/ocamldoc/ b/ocamldoc/
index 8ea2c9477..eb43a9e86 100644
--- a/ocamldoc/
+++ b/ocamldoc/
@@ -26,7 +26,7 @@ module Base_generator : Base = struct
   class generator : doc_generator = object method generate _ = () end
-module type Base_functor = functor (G: Base) -> Base
+module type Base_functor = functor (G: Base) -> Base with type t = int
 module type Html_functor = functor (G: Odoc_html.Html_generator) -> Odoc_html.Html_generator
 module type Latex_functor = functor (G: Odoc_latex.Latex_generator) -> Odoc_latex.Latex_generator
 module type Texi_functor = functor (G: Odoc_texi.Texi_generator) -> Odoc_texi.Texi_generator

And then running make ocamldoc produces:

../boot/ocamlrun ../ocamlc -nostdlib -I ../stdlib -pp 'sh ./remove_DEBUG' -I ../utils -I ../parsing -I ../typing -I ../driver -I ../bytecomp -I ../toplevel -I ../stdlib -I ../compilerlibs -I ../otherlibs/str -I ../otherlibs/dynlink -I ../otherlibs/dynlink/native -I ../otherlibs/unix -absname -w +a-4-9-41-42-44-45-48 -warn-error A -safe-string -strict-sequence -strict-formats -bin-annot -c
File ".../ocamldoc/", line 29, characters 48-70:
29 | ................................................ int
29 | module type Html_...........................................................................
Error: The signature constrained by `with' has no component named t
make[1]: *** [odoc_gen.cmo] Error 2

This comment has been minimized.

Copy link

commented Aug 23, 2019

I investigated this a bit. The issue comes from the fact that, in presence of line directives, locations that are emitted have 1) line numbers that correspond to the file without the line directives (obviously), and 2) column and beginning of line numbers that correspond to the file with the line directives (pos_bol and pos_cnum fields).
That means that in the case of a preprocessor that inserts line directives, the locations that are emitted have line numbers that correspond to the original source file, but beginning of line/end of line numbers that correspond to the file after preprocessing.

I believe this was not an issue in most cases because printing code usually computes pos_cnum - pos_bol for positions in the same line. In that case, the offset that might have been introduced by line directives is cancelled out.
In the new printing code that quotes part of the file, we use pos_bol as an offset in the file from which to start reading the line. Therefore we have an issue if it doesn't correspond to a correct offset in the source file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.