summaryrefslogtreecommitdiff
path: root/typing/primitive.ml
diff options
context:
space:
mode:
authorMarc Lasson <marc.lasson@gmail.com>2016-01-18 18:34:02 +0100
committerMarc Lasson <marc.lasson@gmail.com>2016-01-20 11:51:26 +0100
commit934dd9a40b1512849b689ce97a5204f7f5106d91 (patch)
tree399abe06e45e749c7fcbcd36fae62e90ac6a14f4 /typing/primitive.ml
parent129df0ae09eea80133605c0b4b983bf0ca3ef1f1 (diff)
downloadocaml-934dd9a40b1512849b689ce97a5204f7f5106d91.tar.gz
More errors with unboxed and untagged attributes
This commit adds errors for bad uses of @untagged and @unboxed attributes in external declarations. There are three possible new errors: - One when the external does not contain a native version of the primitive, - One when the attribute occurs deeply into the type, - One when the attribute is applied to the whole function type.
Diffstat (limited to 'typing/primitive.ml')
-rw-r--r--typing/primitive.ml10
1 files changed, 10 insertions, 0 deletions
diff --git a/typing/primitive.ml b/typing/primitive.ml
index efe55b1387..74d6eba1c9 100644
--- a/typing/primitive.ml
+++ b/typing/primitive.ml
@@ -34,6 +34,7 @@ type description =
type error =
| Old_style_float_with_native_repr_attribute
| Old_style_noalloc_with_noalloc_attribute
+ | No_native_primitive_with_repr_attribute
exception Error of Location.t * error
@@ -113,6 +114,11 @@ let parse_declaration valdecl ~native_repr_args ~native_repr_res =
Location.prerr_warning valdecl.pval_loc
(Warnings.Deprecated "[@@noalloc] should be used instead of \
\"noalloc\"");
+ if native_name = "" &&
+ not (List.for_all is_ocaml_repr native_repr_args &&
+ is_ocaml_repr native_repr_res) then
+ raise (Error (valdecl.pval_loc,
+ No_native_primitive_with_repr_attribute));
let noalloc = old_style_noalloc || noalloc_attribute in
let native_repr_args, native_repr_res =
if old_style_float then
@@ -200,6 +206,10 @@ let report_error ppf err =
| Old_style_noalloc_with_noalloc_attribute ->
Format.fprintf ppf "Cannot use \"noalloc\" in conjunction with \
[%@%@noalloc]"
+ | No_native_primitive_with_repr_attribute ->
+ Format.fprintf ppf
+ "The native code version of the primitive is mandatory when \
+ attributes [%@untagged] or [%@unboxed] are present"
let () =
Location.register_error_of_exn