Skip to content

Commit c2a1805

Browse files
committed
pr comments
1 parent 8c13179 commit c2a1805

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

compiler/ml/ast_untagged_variants.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type block_type =
7171
| ObjectType
7272
| UnknownType
7373

74-
let block_type_to_string = function
74+
let block_type_to_user_visible_string = function
7575
| IntType -> "int"
7676
| StringType -> "string"
7777
| FloatType -> "float"
@@ -100,15 +100,15 @@ type tag = {name: string; tag_type: tag_type option}
100100
type block = {tag: tag; tag_name: string option; block_type: block_type option}
101101
type switch_names = {consts: tag array; blocks: block array}
102102

103-
let tag_type_to_string = function
103+
let tag_type_to_user_visible_string = function
104104
| String _ -> "string"
105105
| Int _ -> "int"
106106
| Float _ -> "float"
107107
| BigInt _ -> "bigint"
108108
| Bool _ -> "bool"
109109
| Null -> "null"
110110
| Undefined -> "undefined"
111-
| Untagged block_type -> block_type_to_string block_type
111+
| Untagged block_type -> block_type_to_user_visible_string block_type
112112

113113
let untagged = "unboxed"
114114

compiler/ml/ctype.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ let () =
7272

7373
type subtype_context =
7474
| Generic of {errorCode: string}
75-
| Primitive_coercion_target_variant_not_unboxed of {
75+
| Coercion_target_variant_not_unboxed of {
7676
variant_name: Path.t;
7777
primitive: Path.t;
7878
}
79-
| Primitive_coercion_target_variant_no_catch_all of {
79+
| Coercion_target_variant_does_not_cover_type of {
8080
variant_name: Path.t;
8181
primitive: Path.t;
8282
}
@@ -3660,21 +3660,21 @@ let rec subtype_rec env trace t1 t2 cstrs =
36603660
t2,
36613661
!univar_pairs,
36623662
Some
3663-
(Primitive_coercion_target_variant_not_unboxed
3663+
(Coercion_target_variant_not_unboxed
36643664
{variant_name = p; primitive = path}) )
36653665
:: cstrs
36663666
| Some (p, constructors, true) ->
36673667
if
3668-
Variant_coercion.variant_has_catch_all_case constructors (fun p ->
3669-
Path.same p path)
3668+
Variant_coercion.variant_has_case_covering_type constructors
3669+
~path_is_same_fn:(fun p -> Path.same p path)
36703670
then cstrs
36713671
else
36723672
( trace,
36733673
t1,
36743674
t2,
36753675
!univar_pairs,
36763676
Some
3677-
(Primitive_coercion_target_variant_no_catch_all
3677+
(Coercion_target_variant_does_not_cover_type
36783678
{variant_name = p; primitive = path}) )
36793679
:: cstrs
36803680
| None ->

compiler/ml/ctype.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ open Types
2121
type subtype_context =
2222
| Generic of {errorCode: string}
2323
(** A generic subtype error, intended to be extended to be handled later. *)
24-
| Primitive_coercion_target_variant_not_unboxed of {
24+
| Coercion_target_variant_not_unboxed of {
2525
variant_name: Path.t;
2626
primitive: Path.t;
2727
} (** Coercing a primitive to a variant that is not unboxed. *)
28-
| Primitive_coercion_target_variant_no_catch_all of {
28+
| Coercion_target_variant_does_not_cover_type of {
2929
variant_name: Path.t;
3030
primitive: Path.t;
3131
}

compiler/ml/printtyp.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,17 +1540,16 @@ let print_variant_runtime_representation_issue ppf variant_name
15401540
| Inline_record_cannot_be_coerced {constructor_name} ->
15411541
fprintf ppf
15421542
"The constructor @{<info>%s@} of variant @{<info>%s@} has an inline \
1543-
record as payload. Inline records cannot be coerced."
1543+
record as payload. Currently, inline records cannot be coerced."
15441544
constructor_name (Path.name variant_name)
1545-
| As_payload_cannot_be_coerced
1545+
| As_payload_not_elgible_for_coercion
15461546
{constructor_name; as_payload; expected_typename} ->
15471547
fprintf ppf
15481548
"The constructor @{<info>%s@} of variant @{<info>%s@} has an \
15491549
@{<info>@as@} payload that has a runtime representation of \
1550-
@{<info>%s@}, which is not compatible with the expected of \
1551-
@{<info>%s@}."
1550+
@{<info>%s@}, which is not compatible with the expected @{<info>%s@}."
15521551
constructor_name (Path.name variant_name)
1553-
(Ast_untagged_variants.tag_type_to_string as_payload)
1552+
(Ast_untagged_variants.tag_type_to_user_visible_string as_payload)
15541553
(Path.name expected_typename)
15551554
| Mismatched_unboxed_payload _ -> ()
15561555
| Mismatched_as_payload {constructor_name; expected_typename; as_payload} ->
@@ -1565,7 +1564,7 @@ let print_variant_runtime_representation_issue ppf variant_name
15651564
fprintf ppf
15661565
"an @{<info>@as@} payload that gives it the runtime type of \
15671566
@{<info>%s@}."
1568-
(Ast_untagged_variants.tag_type_to_string payload));
1567+
(Ast_untagged_variants.tag_type_to_user_visible_string payload));
15691568
fprintf ppf
15701569
"@ That runtime representation is not compatible with the expected \
15711570
runtime representation of @{<info>%s@}."
@@ -1704,16 +1703,15 @@ let report_subtyping_error ppf env tr1 txt1 tr2 ctx =
17041703
fprintf ppf "@,@,@[<v 2>";
17051704
match ctx with
17061705
| Generic {errorCode} -> fprintf ppf "Error: %s" errorCode
1707-
| Primitive_coercion_target_variant_not_unboxed
1708-
{variant_name; primitive} ->
1706+
| Coercion_target_variant_not_unboxed {variant_name; primitive} ->
17091707
fprintf ppf
17101708
"@ The variant @{<info>%s@} is not unboxed, so it cannot be \
17111709
coerced to a @{<info>%s@}. @ Fix this by adding the \
17121710
@{<info>@unboxed@} attribute to the variant @{<info>%s@}."
17131711
(Path.name variant_name) (Path.name primitive)
17141712
(Path.name variant_name)
1715-
| Primitive_coercion_target_variant_no_catch_all
1716-
{variant_name; primitive} ->
1713+
| Coercion_target_variant_does_not_cover_type {variant_name; primitive}
1714+
->
17171715
fprintf ppf
17181716
"@ The variant @{<info>%s@} is unboxed, but has no catch-all case \
17191717
for the primitive @{<info>%s@}, and therefore does not cover all \

compiler/ml/variant_coercion.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type variant_runtime_representation_issue =
88
expected_typename: Path.t;
99
as_payload: Ast_untagged_variants.tag_type option;
1010
}
11-
| As_payload_cannot_be_coerced of {
11+
| As_payload_not_elgible_for_coercion of {
1212
constructor_name: string;
1313
expected_typename: Path.t;
1414
as_payload: Ast_untagged_variants.tag_type;
@@ -29,12 +29,12 @@ let can_coerce_primitive (path : Path.t) =
2929
let check_paths_same p1 p2 target_path =
3030
Path.same p1 target_path && Path.same p2 target_path
3131

32-
let variant_has_catch_all_case
33-
(constructors : Types.constructor_declaration list) path_is_same =
32+
let variant_has_case_covering_type
33+
(constructors : Types.constructor_declaration list) ~path_is_same_fn =
3434
let has_catch_all_string_case (c : Types.constructor_declaration) =
3535
let args = c.cd_args in
3636
match args with
37-
| Cstr_tuple [{desc = Tconstr (p, [], _)}] -> path_is_same p
37+
| Cstr_tuple [{desc = Tconstr (p, [], _)}] -> path_is_same_fn p
3838
| _ -> false
3939
in
4040

@@ -114,7 +114,7 @@ let variant_has_same_runtime_representation_as_target ~(target_path : Path.t)
114114
})
115115
| Some ((Null | Undefined | Bool _ | Untagged _) as as_payload) ->
116116
Some
117-
(As_payload_cannot_be_coerced
117+
(As_payload_not_elgible_for_coercion
118118
{
119119
constructor_name = Ident.name c.cd_id;
120120
as_payload;

tests/build_tests/super_errors/expected/variant_coercion_inline_record.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
Type x is not a subtype of string
1111

12-
The constructor One of variant x has an inline record as payload. Inline records cannot be coerced.
12+
The constructor One of variant x has an inline record as payload. Currently, inline records cannot be coerced.

0 commit comments

Comments
 (0)