Skip to content

Commit

Permalink
Support OCaml 4.09 (#2450)
Browse files Browse the repository at this point in the history
* Support OCaml 4.09

* fix oprint for older versions
  • Loading branch information
anmonteiro authored and jordwalke committed Sep 23, 2019
1 parent 31225fc commit ba253a3
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ jobs:
- OCAML_VERSION: "4.08.x"
- NPM_CONFIG_PREFIX: "~/.npm-global"
<<: *common_steps
4.09.0:
docker:
- image: ocaml/opam2:debian-9-ocaml-4.09
environment:
- TERM: dumb
- OCAML_VERSION: "4.09.x"
- NPM_CONFIG_PREFIX: "~/.npm-global"
<<: *common_steps
esy_build:
docker:
- image: ocaml/opam2:debian-9-ocaml-4.06
Expand Down Expand Up @@ -170,4 +178,5 @@ workflows:
- 4.06.1
- 4.07.0
- 4.08.0
- 4.09.0
- esy_build
11 changes: 11 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ jobs:
steps:
- template: .ci/esy-build-steps.yml

- job: Mac_opam_4090
timeoutInMinutes: 0
pool:
vmImage: 'macOS 10.13'

variables:
OCAML_VERSION: 4.09.0

steps:
- template: .ci/opam-build-steps.yml

- job: Mac_opam_4080
timeoutInMinutes: 0
pool:
Expand Down
5 changes: 5 additions & 0 deletions formatTest/errorTests/expected_output/comments1.re.4.09.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "comments1.re", line 1, characters 0-2:
1 | /* this is an unterminated comment
^^
Error: Comment not terminated

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "lowercase_module.re", line 1, characters 7-16:
1 | module lowercase = {};
^^^^^^^^^
Error: Module names must start with an uppercase letter.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "lowercase_module_rec.re", line 1, characters 11-20:
1 | module rec lowercase = {};
^^^^^^^^^
Error: Module names must start with an uppercase letter.

5 changes: 5 additions & 0 deletions formatTest/errorTests/expected_output/reservedField.re.4.09.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "reservedField.re", line 1, characters 11-15:
1 | let x = {< type >};
^^^^
Error: 1054: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "reservedRecord.re", line 1, characters 24-28:
1 | let foo = { foo: "bar", type: "qux" };
^^^^
Error: 1863: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "reservedRecordPunned.re", line 1, characters 22-26:
1 | let foo = { ...other, type };
^^^^
Error: 3411: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "reservedRecordType.re", line 1, characters 11-15:
1 | type x = { type: string };
^^^^
Error: 770: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "reservedRecordTypePunned.re", line 1, characters 11-15:
1 | type x = { type };
^^^^
Error: 770: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

5 changes: 5 additions & 0 deletions formatTest/errorTests/expected_output/syntaxError.re.4.09.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File "syntaxError.re", line 1, characters 9-10:
1 | try (bad);
^
Error: Syntax error

39 changes: 39 additions & 0 deletions formatTest/typeCheckedTests/expected_output/comments.rei.4.09.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* **** comment */
/*** comment */
/** docstring */;
/* comment */
/** docstring */;
/*** comment */
/**** comment */
/***** comment */

/** */;
/*** */
/**** */

/***/
/****/

/** (** comment *) */;
/** (*** comment *) */;

/* (** comment *) */
/* (*** comment *) */
/* *(*** comment *) */

/* comment **/
/* comment ***/
/* comment ****/
/* comment *****/

/**
* Multiline
*/;

/** Multiline
*
*/;

/**
**
*/;
27 changes: 27 additions & 0 deletions formatTest/typeCheckedTests/expected_output/mlVariants.re.4.09.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */

type polyVariantsInMl = [
| `IntTuple(int, int)
| `StillAnIntTuple(int, int)
];

let intTuple = `IntTuple((1, 2));
let stillAnIntTuple = `StillAnIntTuple((4, 5));
let sumThem =
fun
| `IntTuple(x, y) => x + y
| `StillAnIntTuple(a, b) => a + b;

type nonrec t =
| A(int)
| B(bool);

type s = [ | `Poly];

let x: s = `Poly;

/* There's a bug in ocaml 4.06 resulting in an extra Pexp_constraint on the `Poly,
* duplicating the core_type.
* https://caml.inria.fr/mantis/view.php?id=7758
* https://caml.inria.fr/mantis/view.php?id=7344 */
let x: s = (`Poly: s);
2 changes: 1 addition & 1 deletion reason.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "4.02" & < "4.09"}
"ocaml" {>= "4.02" & < "4.10"}
"dune" {>= "1.4"}
"ocamlfind" {build}
"menhir" {>= "20170418"}
Expand Down
2 changes: 1 addition & 1 deletion rtop.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "4.02" & < "4.09"}
"ocaml" {>= "4.02" & < "4.10"}
"dune" {>= "1.4"}
"reason"
"utop" {>= "1.17"}
Expand Down
6 changes: 6 additions & 0 deletions src/reason-parser-tests/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
(rule
(targets testOprint.ml)
(deps testOprint.cppo.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{deps} -o %{targets})))

(executable
(name testOprint)
(libraries reason))
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ let main () =
let lexbuf = Reason_toolchain.setup_lexbuf true filename in
let impl = Reason_toolchain.RE.implementation in

#if OCAML_VERSION >= (4,9,0)
Compmisc.init_path ();
#else
Compmisc.init_path false;
#endif
Env.set_unit_name modulename;

let ast = impl lexbuf in
Expand Down
16 changes: 8 additions & 8 deletions src/reason-parser/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

(rule
(targets lexer_warning.ml)
(deps ../generate/select.exe lexer_warning.ml-4.08 lexer_warning.ml-4.07
lexer_warning.ml-4.06 lexer_warning.ml-default)
(deps ../generate/select.exe lexer_warning.ml-4.09 lexer_warning.ml-4.08
lexer_warning.ml-4.07 lexer_warning.ml-4.06 lexer_warning.ml-default)
(action
(with-stdout-to
%{targets}
(run ../generate/select.exe lexer_warning.ml-4.08 lexer_warning.ml-4.07
lexer_warning.ml-4.06 lexer_warning.ml-default))))
(run ../generate/select.exe lexer_warning.ml-4.09 lexer_warning.ml-4.08
lexer_warning.ml-4.07 lexer_warning.ml-4.06 lexer_warning.ml-default))))

(rule
(targets reason_string.ml)
Expand All @@ -23,13 +23,13 @@

(rule
(targets lexer_report_error.ml)
(deps ../generate/select.exe lexer_report_error.ml-4.08
lexer_report_error.ml-default)
(deps ../generate/select.exe lexer_report_error.ml-4.09
lexer_report_error.ml-4.08 lexer_report_error.ml-default)
(action
(with-stdout-to
%{targets}
(run ../generate/select.exe lexer_report_error.ml-4.08
lexer_report_error.ml-default))))
(run ../generate/select.exe lexer_report_error.ml-4.09
lexer_report_error.ml-4.08 lexer_report_error.ml-default))))

; Update error messages based on new grammar
; Previously, called update_error in the `Makefile`.
Expand Down
4 changes: 4 additions & 0 deletions src/reason-parser/lexer_report_error.ml-4.09
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let report_error ppf ~loc err =
Format.fprintf ppf "@[%a@]@."
Location.print_report
(Location.error_of_printer ~loc Reason_lexer.format_error err)
3 changes: 3 additions & 0 deletions src/reason-parser/lexer_warning.ml-4.09
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let warn_latin1 lexbuf =
Location.deprecated (Location.curr lexbuf) "ISO-Latin1 characters in identifiers"
;;

0 comments on commit ba253a3

Please sign in to comment.