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
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/res_core.ml
Original file line number Diff line number Diff line change
@@ -5408,11 +5408,15 @@ and parseJsImport ~startPos ~attrs p =
let importSpec =
match p.Parser.token with
| Token.Lident _ | Token.At ->
Parser.leaveBreadcrumb p Grammar.JsFfiImport;
let decl =
match parseJsFfiDeclaration p with
| Some decl -> decl
| None -> assert false
| None ->
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs);
JsFfi.emptyDecl p.startPos
in
Parser.eatBreadcrumb p;
JsFfi.Default decl
| _ -> JsFfi.Spec (parseJsFfiDeclarations p)
in
13 changes: 13 additions & 0 deletions src/res_js_ffi.ml
Original file line number Diff line number Diff line change
@@ -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;
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@