-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Errors for marshalled ASTs no longer print relevant source code #12697
Description
I'm pretty sure this is caused by #12403. I believe it's a regression because I don't see it acknowledged as a consequence in the discussion there, but it's possible it was intended, in which case just close this.
Here is an incorrect program:
let x : int = trueOn trunk, we print the error differently depending on whether the source file itself is passed to the compiler, or we pass a marshalled AST. Here is the error for the former:
File "foo.ml", line 1, characters 14-18:
1 | let x : int = true
^^^^
Error: This expression has type bool but an expression was expected of type
int
And here is the latter:
File "foo.ml", line 1, characters 14-18:
Error: This expression has type bool but an expression was expected of type
int
To produce the latter, put the bad program in a file named foo.ml, and then run this script in the toplevel:
#directory "+compiler-libs";;
#load "ocamlcommon.cma";;
let ast = Pparse.parse_implementation ~tool_name:"test" "foo.ml";;
Pparse.write_ast Pparse.Structure "foo.marshalled.ml" ast;;(And then run the compiler on the resulting foo.marshaled.ml)
I haven't read the code of #12403, but based on the description I suspect the issue is that when compiling marshalled asts, we relied entirely on the "fallback" path of re-reading the source file to give nice errors, and that fallback has been removed.
(I noticed this while rebasing #12451, which adds a test that the reworked warning 53 works appropriately for marshalled asts. I only have that test there because I got it wrong initially, but probably we should have more such tests.)
cc @gasche