Skip to content

Commit da94a3c

Browse files
committed
Merge branch 'master' into add-attr-syntax-sugar-array
2 parents 35c0d0d + 6e2bf19 commit da94a3c

23 files changed

+332
-300
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#### :nail_care: Polish
2424
- Conditionally print error message about record with missing label potentially being a component. https://github.com/rescript-lang/rescript-compiler/pull/6337
2525
- Put definition in the bottom and the actual error at the top when reporting errors for supplying fields etc with the wrong name. https://github.com/rescript-lang/rescript-compiler/pull/6336
26+
- Fix left over places where polyvariant tag names were printed in OCaml syntax instead of ReScript. https://github.com/rescript-lang/rescript-compiler/pull/6348
2627

2728
# 11.0.0-beta.4
2829

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/polyvariant_name_formatting.res:6:3-10
4+
5+
4 │
6+
5 │ switch f {
7+
6 │ | #Invalid => ()
8+
7 │ }
9+
8 │
10+
11+
This pattern matches values of type [? #Invalid]
12+
but a pattern was expected which matches values of type polyvariant
13+
The second variant type does not allow tag(s) #Invalid
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type polyvariant = [#Error(string) | #Valid]
2+
3+
let f: polyvariant = #Valid
4+
5+
switch f {
6+
| #Invalid => ()
7+
}

jscomp/core/bs_conditional_initial.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ let setup_env () =
5252

5353
Rescript_cpp.replace_directive_bool "BS" true;
5454
Rescript_cpp.replace_directive_bool "JS" true;
55+
Printtyp.print_res_poly_identifier := Res_printer.polyVarIdentToString;
5556
Rescript_cpp.replace_directive_string "BS_VERSION" Bs_version.version
5657
(*; Switch.cut := 100*) (* tweakable but not very useful *)
58+
5759

5860
let () =
5961
at_exit (fun _ -> Format.pp_print_flush Format.err_formatter ())

jscomp/gentype/EmitType.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
163163
type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType)
164164
in
165165
let noPayloadsRendered = noPayloads |> List.map labelJSToString in
166-
let field ~name ?(docString = DocString.empty) value =
166+
let field ~name value =
167167
{
168168
mutable_ = Mutable;
169169
nameJS = name;
170170
optional = Mandatory;
171171
type_ = TypeVar value;
172-
docString;
172+
docString = DocString.empty;
173173
}
174174
in
175175
let fields fields =

jscomp/ml/ctype.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let () =
6565
Some
6666
Location.
6767
(errorf ~loc:(in_file !input_name)
68-
"In this program,@ variant constructors@ `%s and `%s@ \
68+
"In this program,@ variant constructors@ #%s and #%s@ \
6969
have the same hash value.@ Change one of them." l l'
7070
)
7171
| _ -> None

jscomp/ml/printtyp.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ open Types
2525
open Btype
2626
open Outcometree
2727

28+
let print_res_poly_identifier: (string -> string) ref = ref (fun _ -> assert false)
29+
2830
(* Print a long identifier *)
2931

3032
let rec longident ppf = function
@@ -1412,8 +1414,8 @@ let may_prepare_expansion compact (t, t') =
14121414
let print_tags ppf fields =
14131415
match fields with [] -> ()
14141416
| (t, _) :: fields ->
1415-
fprintf ppf "`%s" t;
1416-
List.iter (fun (t, _) -> fprintf ppf ",@ `%s" t) fields
1417+
fprintf ppf "%s" (!print_res_poly_identifier t);
1418+
List.iter (fun (t, _) -> fprintf ppf ",@ %s" (!print_res_poly_identifier t)) fields
14171419

14181420
let has_explanation t3 t4 =
14191421
match t3.desc, t4.desc with
@@ -1493,7 +1495,7 @@ let explanation unif t3 t4 ppf =
14931495
"@,@[The second variant type does not allow tag(s)@ @[<hov>%a@]@]"
14941496
print_tags fields
14951497
| [l1,_], true, [l2,_], true when l1 = l2 ->
1496-
fprintf ppf "@,Types for tag `%s are incompatible" l1
1498+
fprintf ppf "@,Types for tag %s are incompatible" (!print_res_poly_identifier l1)
14971499
| _ -> ()
14981500
end
14991501
| _ -> ()

jscomp/ml/printtyp.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ open Format
1919
open Types
2020
open Outcometree
2121

22+
val print_res_poly_identifier: (string -> string) ref
2223
val longident: formatter -> Longident.t -> unit
2324
val ident: formatter -> Ident.t -> unit
2425
val tree_of_path: Path.t -> out_ident

jscomp/ml/typetexp.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,8 @@ let report_error env ppf = function
946946
end
947947
| Variant_tags (lab1, lab2) ->
948948
fprintf ppf
949-
"@[Variant tags `%s@ and `%s have the same hash value.@ %s@]"
950-
lab1 lab2 "Change one of them."
949+
"@[Variant tags %s@ and %s have the same hash value.@ %s@]"
950+
(!Printtyp.print_res_poly_identifier lab1) (!Printtyp.print_res_poly_identifier lab2) "Change one of them."
951951
| Invalid_variable_name name ->
952952
fprintf ppf "The type variable name %s is not allowed in programs" name
953953
| Cannot_quantify (name, v) ->

jscomp/syntax/src/res_printer.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ let printPolyVarIdent txt =
480480
| "" -> Doc.concat [Doc.text "\""; Doc.text txt; Doc.text "\""]
481481
| _ -> Doc.text txt)
482482

483+
let polyVarIdentToString polyVarIdent =
484+
Doc.concat [Doc.text "#"; printPolyVarIdent polyVarIdent]
485+
|> Doc.toString ~width:80
486+
483487
let printLident l =
484488
let flatLidOpt lid =
485489
let rec flat accu = function

jscomp/syntax/src/res_printer.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ val printImplementation :
2424
width:int -> Parsetree.structure -> comments:Res_comment.t list -> string
2525
val printInterface :
2626
width:int -> Parsetree.signature -> comments:Res_comment.t list -> string
27+
28+
val polyVarIdentToString : string -> string [@@live]

jscomp/test/demo_int_map.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/int_map.js

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)