Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#### :bug: Bug fix

- Fix code generation for emojis in polyvars and labels. https://github.com/rescript-lang/rescript/pull/7853
- Fix crash with `@get` on external of type `unit => 'a`. https://github.com/rescript-lang/rescript/pull/7866

#### :memo: Documentation

Expand Down
6 changes: 5 additions & 1 deletion compiler/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ let translate_ffi ?(transformed_jsx = false) (cxt : Lam_compile_context.t)
| [obj] ->
let obj = translate_scoped_access scopes obj in
E.dot obj name
| _ -> assert false
| _ ->
(* This should have been caught in the frontend validation. *)
invalid_arg
"Internal compiler error: @get external called with wrong number of \
arguments. Expected exactly one object argument."
(* Note these assertion happens in call site *))
| Js_set {js_set_name = name; js_set_scopes = scopes} -> (
(* assert (js_splice = false) ; *)
Expand Down
7 changes: 6 additions & 1 deletion compiler/frontend/ast_external_process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,12 @@ let external_desc_of_non_obj (loc : Location.t) (st : external_desc)
tagged_template = _;
} ->
if arg_type_specs_length = 1 then
Js_get {js_get_name = name; js_get_scopes = scopes}
(* Check if the first argument is unit, which is invalid for @get *)
match arg_type_specs with
| [{arg_type = Extern_unit}] ->
Location.raise_errorf ~loc
"Ill defined attribute %@get (unit argument is not allowed)"
| _ -> Js_get {js_get_name = name; js_get_scopes = scopes}
else
Location.raise_errorf ~loc
"Ill defined attribute %@get (only one argument)"
Expand Down
12 changes: 12 additions & 0 deletions tests/build_tests/super_errors/expected/get_unit_arg.res.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

We've found a bug for you!
/.../fixtures/get_unit_arg.res:2:1-3:36

1 │ // Test case for issue #7676 - @get external with unit => 'a should give
│ proper error
2 │ @get
3 │ external foo: unit => string = "foo"
4 │
5 │ let x = foo()

Ill defined attribute @get (unit argument is not allowed)
5 changes: 5 additions & 0 deletions tests/build_tests/super_errors/fixtures/get_unit_arg.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test case for issue #7676 - @get external with unit => 'a should give proper error
@get
external foo: unit => string = "foo"

let x = foo()
Loading