Skip to content

Commit d36b5b3

Browse files
committed
Error if @notundefined is used on a non-abstract type
1 parent b1b5d36 commit d36b5b3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler/ml/typedecl.ml

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type error =
4949
| Unbound_type_var_ext of type_expr * extension_constructor
5050
| Varying_anonymous
5151
| Val_in_structure
52+
| InvalidAttribute of string
5253
| Bad_immediate_attribute
5354
| Bad_unboxed_attribute of string
5455
| Boxed_and_unboxed
@@ -295,6 +296,20 @@ let make_constructor env type_path type_params sargs sret_type =
295296
*)
296297

297298
let transl_declaration ~type_record_as_object ~untagged_wfc env sdecl id =
299+
(* Check for @notUndefined attribute *)
300+
let has_not_undefined =
301+
List.exists (fun ({txt}, _) -> txt = "notUndefined") sdecl.ptype_attributes
302+
in
303+
(if has_not_undefined then
304+
match (sdecl.ptype_kind, sdecl.ptype_manifest) with
305+
| Ptype_abstract, None -> ()
306+
| _ ->
307+
raise
308+
(Error
309+
( sdecl.ptype_loc,
310+
InvalidAttribute
311+
"@notUndefined can only be used on abstract types" )));
312+
298313
(* Bind type parameters *)
299314
reset_type_variables ();
300315
Ctype.begin_def ();
@@ -2090,6 +2105,7 @@ let report_error ppf = function
20902105
"The field @{<info>%s@} is defined several times in this record. Fields \
20912106
can only be added once to a record."
20922107
s
2108+
| InvalidAttribute msg -> fprintf ppf "%s" msg
20932109
| Duplicate_label (s, Some record_name) ->
20942110
fprintf ppf
20952111
"The field @{<info>%s@} is defined several times in the record \

0 commit comments

Comments
 (0)