From 3a73532c3e5c434fa5ab3fc1e88f0bcc57cda7bb Mon Sep 17 00:00:00 2001 From: Sehoon Kim Date: Fri, 1 Jul 2022 14:42:06 +0900 Subject: [PATCH 1/2] fix import bug --- src/res_core.ml | 2 +- src/res_js_ffi.ml | 13 +++++++++++++ tests/parsing/errors/other/expected/import.res.txt | 10 ++++++++++ tests/parsing/errors/other/import.res | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/parsing/errors/other/expected/import.res.txt create mode 100644 tests/parsing/errors/other/import.res diff --git a/src/res_core.ml b/src/res_core.ml index 31258253..092ef4f4 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -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 in JsFfi.Default decl | _ -> JsFfi.Spec (parseJsFfiDeclarations p) diff --git a/src/res_js_ffi.ml b/src/res_js_ffi.ml index 3d02fb10..12a4ae2a 100644 --- a/src/res_js_ffi.ml +++ b/src/res_js_ffi.ml @@ -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; diff --git a/tests/parsing/errors/other/expected/import.res.txt b/tests/parsing/errors/other/expected/import.res.txt new file mode 100644 index 00000000..6af348b9 --- /dev/null +++ b/tests/parsing/errors/other/expected/import.res.txt @@ -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") diff --git a/tests/parsing/errors/other/import.res b/tests/parsing/errors/other/import.res new file mode 100644 index 00000000..74d56807 --- /dev/null +++ b/tests/parsing/errors/other/import.res @@ -0,0 +1 @@ +import@ From a2e9851eb02680e6aa524ead60db91bf568c46ae Mon Sep 17 00:00:00 2001 From: Sehoon Kim Date: Sat, 2 Jul 2022 14:26:31 +0900 Subject: [PATCH 2/2] add parseJsImport error handling --- src/res_core.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/res_core.ml b/src/res_core.ml index 092ef4f4..f6747806 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -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 -> JsFfi.emptyDecl p.startPos + | 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