Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Assertion of parseJsImport fails #593

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5411,7 +5411,7 @@ and parseJsImport ~startPos ~attrs p =
let decl =
match parseJsFfiDeclaration p with
| Some decl -> decl
| None -> assert false
| None -> JsFfi.emptyDecl p.startPos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how other errors are handled.
E.g. just a few lines above here:

Parser.err ~startPos:attrLoc.loc_start ~endPos:attrLoc.loc_end p
        (Diagnostics.message (ErrorMessages.attributeWithoutNode attr));

Currently it goes all the way to the end of the file silently (e.g. in the provided test).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see this example for where to define the default value to use (inside Recover:

    Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
    Recover.defaultModuleExpr ()

in
JsFfi.Default decl
| _ -> JsFfi.Spec (parseJsFfiDeclarations p)
Expand Down
13 changes: 13 additions & 0 deletions src/res_js_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ let decl ~attrs ~loc ~name ~alias ~typ =
jld_type = typ;
}

let emptyDecl loc =
let loc = Location.{loc_start = loc; loc_end = loc; loc_ghost = false} in
let emptyCoreType : Parsetree.core_type =
{ptyp_desc = Parsetree.Ptyp_any; ptyp_loc = loc; ptyp_attributes = []}
in
{
jld_loc = loc;
jld_attributes = [];
jld_name = "";
jld_alias = "";
jld_type = emptyCoreType;
}

let importDescr ~attrs ~scope ~importSpec ~loc =
{
jid_loc = loc;
Expand Down
10 changes: 10 additions & 0 deletions tests/parsing/errors/other/expected/import.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Syntax error!
tests/parsing/errors/other/import.res:2:1

1 │ import@
2 │

I'm not sure what to parse here when looking at "eof".

include struct external Fatal error: exception Invalid_argument("index out of bounds")
1 change: 1 addition & 0 deletions tests/parsing/errors/other/import.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import@