Skip to content

Errors for marshalled ASTs no longer print relevant source code #12697

@ccasin

Description

@ccasin

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 = true

On 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions