@@ -195,13 +195,13 @@ let attr_names attrs = List.map (fun ({Location.txt}, _) -> txt) attrs
195195let test_list_constructor_wire_shape _ =
196196 let lid name = Location. mknoloc (Longident. Lident name) in
197197 List. iter
198- (fun attrs ->
198+ (fun ( attrs , payload_attrs ) ->
199199 let expr0 =
200200 List. fold_right
201201 (fun value tail ->
202202 Ast_helper0.Exp. construct ~loc ~attrs (lid " ::" )
203203 (Some
204- (Ast_helper0.Exp. tuple ~loc
204+ (Ast_helper0.Exp. tuple ~loc ~attrs: payload_attrs
205205 [
206206 Ast_helper0.Exp. constant ~loc
207207 (Parsetree0. Pconst_integer (value, None ));
@@ -215,24 +215,46 @@ let test_list_constructor_wire_shape _ =
215215 (fun name tail ->
216216 Ast_helper0.Pat. construct ~loc ~attrs (lid " ::" )
217217 (Some
218- (Ast_helper0.Pat. tuple ~loc
218+ (Ast_helper0.Pat. tuple ~loc ~attrs: payload_attrs
219219 [Ast_helper0.Pat. var ~loc (Location. mknoloc name); tail])))
220220 [" head" ; " next" ]
221221 (Ast_helper0.Pat. construct ~loc (lid " []" ) None )
222222 in
223223 let expr = map_expr0 expr0 in
224224 let pat = map_pat0 pat0 in
225- (match (expr.pexp_desc, pat.ppat_desc) with
226- | Pexp_construct (_, {txt = [_; _]}), Ppat_construct (_, {txt = [_; _]})
227- ->
225+ (match (payload_attrs, expr.pexp_desc, pat.ppat_desc) with
226+ | ( [] ,
227+ Pexp_construct (_, {txt = [_; _]}),
228+ Ppat_construct (_, {txt = [_; _]}) ) ->
229+ ()
230+ | ( _ :: _,
231+ Pexp_construct (_, {txt = [{pexp_desc = Pexp_tuple [_; _]}]}),
232+ Ppat_construct (_, {txt = [{ppat_desc = Ppat_tuple [_; _]}]}) ) ->
228233 ()
229234 | _ ->
230- assert_failure " Unmarked cons payloads must decode to two arguments " );
235+ assert_failure " Attributed cons payloads must retain their tuple node " );
231236 OUnit. assert_equal ~msg: " list expression wire shape and attributes" expr0
232237 (map_expr_to0 expr);
233238 OUnit. assert_equal ~msg: " list pattern wire shape and attributes" pat0
234- (map_pat_to0 pat))
235- [[]; [attr " public_attr" (Parsetree0. PStr [] )]]
239+ (map_pat_to0 pat);
240+ let structure =
241+ [
242+ Ast_helper.Str. value ~loc Nonrecursive [Ast_helper.Vb. mk ~loc pat expr];
243+ ]
244+ in
245+ ignore (Typemod. type_structure Env. initial_safe_string structure loc);
246+ let printed =
247+ Res_printer. print_implementation structure ~comments: [] ~width: 80
248+ in
249+ let parsed =
250+ Res_driver. parse_implementation_from_source
251+ ~display_filename: " ListPayloadAttributes.res" ~source: printed
252+ in
253+ OUnit. assert_bool " attributed list payloads remain printable"
254+ (not parsed.invalid);
255+ ignore (Format. asprintf " %a" Pprintast. structure structure))
256+ (let attrs = [attr " public_attr" (Parsetree0. PStr [] )] in
257+ [([] , [] ); (attrs, [] ); ([] , attrs); (attrs, attrs)])
236258
237259let test_constructor_args_roundtrip_through_ast0 _ =
238260 let int_expr value =
0 commit comments