Skip to content

Commit 8a232ae

Browse files
committed
Keep field renames in object spreads
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent 3252a01 commit 8a232ae

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#### :bug: Bug fix
3838

3939
- Fix the side-effect analysis treating bigint exponentiation and bounds-checked array and string reads as pure, which let dead-code elimination drop an unused one that throws: `let _ = 2n ** -1n` no longer raised. https://github.com/rescript-lang/rescript/pull/8617
40+
- Preserve record field `@as` annotations when formatting object types containing spreads. https://github.com/rescript-lang/rescript/pull/8619
4041
- Fix excessive parentheses and indentation in function assignments to refs, align record and array assignment formatting across refs and fields, and preserve function return-type parentheses and consistent JSX fragment layout in callbacks. https://github.com/rescript-lang/rescript/pull/8611
4142
- Report an error instead of crashing when an integer in a variant constructor's `@as` annotation exceeds the compiler's integer range. https://github.com/rescript-lang/rescript/pull/8619
4243
- Warn about an `@as` on a record field whose payload does not name the field, such as `@as(42)`. It renamed nothing and was silently accepted. https://github.com/rescript-lang/rescript/pull/8619

compiler/syntax/src/res_core.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,13 +5892,13 @@ and parse_spread_tail_classified ?current_type_name_path ?inline_types_context
58925892
(* Object-style: build an object type that inherits the spread *)
58935893
let obj_fields =
58945894
let convert (ld : Parsetree.label_declaration) =
5895-
let ({Parsetree.pld_name; pld_type; pld_attributes; _}
5896-
: Parsetree.label_declaration) =
5895+
let ({Parsetree.pld_name; pld_type; _} : Parsetree.label_declaration)
5896+
=
58975897
ld
58985898
in
58995899
match pld_name.txt with
59005900
| "..." -> Parsetree.Oinherit pld_type
5901-
| _ -> Otag (pld_name, pld_attributes, pld_type)
5901+
| _ -> Otag (pld_name, Ast_helper.Type.field_attributes ld, pld_type)
59025902
in
59035903
Parsetree.Oinherit spread_typ :: List.map convert fields
59045904
in
@@ -5979,7 +5979,9 @@ and parse_record_or_object_decl ?current_type_name_path ?inline_types_context p
59795979
Ext_list.map fields (fun ld ->
59805980
match ld.pld_name.txt with
59815981
| "..." -> Parsetree.Oinherit ld.pld_type
5982-
| _ -> Otag (ld.pld_name, ld.pld_attributes, ld.pld_type))
5982+
| _ ->
5983+
Otag
5984+
(ld.pld_name, Ast_helper.Type.field_attributes ld, ld.pld_type))
59835985
in
59845986
let dot_field = Parsetree.Oinherit typ in
59855987
let typ_obj = Ast_helper.Typ.object_ (dot_field :: fields) Closed in
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type base = {"a": int}
2+
3+
type extended = {...base, @as("renamed") "b": int}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type base = {"a": int}
2+
3+
type extended = {...base, @as("renamed") "b": int}

0 commit comments

Comments
 (0)