Skip to content

Type constraint on return type of anonymous functions is now always printed before the function body#1381

Merged
gpetiot merged 3 commits intoocaml-ppx:masterfrom
gpetiot:preserve-return-type-constraint
Jun 10, 2020
Merged

Type constraint on return type of anonymous functions is now always printed before the function body#1381
gpetiot merged 3 commits intoocaml-ppx:masterfrom
gpetiot:preserve-return-type-constraint

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented May 27, 2020

Fix #1368, no diff with test_branch

@jberdine
Copy link
Copy Markdown
Collaborator

jberdine commented Jun 4, 2020

Does this absolutely have to be "preserve"? I'd much rather we always emitted the form requested in the linked issue.

@gpetiot gpetiot changed the title Preserve return type constraint position Type constraint on return type of anonymous functions is now always printed before the function body Jun 5, 2020
@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jun 5, 2020

Does this absolutely have to be "preserve"? I'd much rather we always emitted the form requested in the linked issue.

It's better indeed, I updated the PR.
Here is the test_branch diff: (which looks good)

diff --git a/infer/src/IR/Subtype.ml b/infer/src/IR/Subtype.ml
index cec7e765d..c6914040e 100644
--- a/infer/src/IR/Subtype.ml
+++ b/infer/src/IR/Subtype.ml
@@ -72,13 +72,12 @@ end)
 
 let check_subtype =
   let subtMap = ref SubtypesMap.empty in
-  fun tenv c1 c2 ->
-    ( try SubtypesMap.find (c1, c2) !subtMap
-      with Caml.Not_found ->
-        let is_subt = check_subclass_tenv tenv c1 c2 in
-        subtMap := SubtypesMap.add (c1, c2) is_subt !subtMap;
-        is_subt
-      : result )
+  fun tenv c1 c2 : result ->
+    try SubtypesMap.find (c1, c2) !subtMap
+    with Caml.Not_found ->
+      let is_subt = check_subclass_tenv tenv c1 c2 in
+      subtMap := SubtypesMap.add (c1, c2) is_subt !subtMap;
+      is_subt
 
 let is_known_subtype tenv c1 c2 : bool =
   equal_result (check_subtype tenv c1 c2) Yes
diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml
index e2ef94e13..21a8100c3 100644
--- a/infer/src/java/jTrans.ml
+++ b/infer/src/java/jTrans.ml
@@ -407,9 +407,8 @@ let create_cm_procdesc source_file program icfg cm proc_name =
     let formals = translate_formals program tenv cn jbir_code in
     let locals_ = translate_locals program tenv formals bytecode jbir_code in
     let locals =
-      List.map locals_ ~f:(fun (name, typ) ->
-          ( { name; typ; modify_in_block = false; is_constexpr = false }
-            : ProcAttributes.var_data ) )
+      List.map locals_ ~f:(fun (name, typ) : ProcAttributes.var_data ->
+          { name; typ; modify_in_block = false; is_constexpr = false } )
     in
     let method_annotation =
       JAnnotation.translate_method cm.Javalib.cm_annotations
diff --git a/sledge/bin/sledge_cli.ml b/sledge/bin/sledge_cli.ml
index 7d18cdbb9..83a61ca42 100644
--- a/sledge/bin/sledge_cli.ml
+++ b/sledge/bin/sledge_cli.ml
@@ -64,7 +64,7 @@ let marshal program file =
   Out_channel.with_file file ~f:(fun oc -> Marshal.to_channel oc program [])
 
 let unmarshal file () =
-  In_channel.with_file ~f:(fun ic -> (Marshal.from_channel ic : Llair.t)) file
+  In_channel.with_file ~f:(fun ic : Llair.t -> Marshal.from_channel ic) file

Copy link
Copy Markdown
Collaborator

@jberdine jberdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@gpetiot gpetiot merged commit 5edea56 into ocaml-ppx:master Jun 10, 2020
@gpetiot gpetiot deleted the preserve-return-type-constraint branch June 10, 2020 06:25
emillon added a commit to emillon/opam-repository that referenced this pull request Aug 6, 2020
CHANGES:

#### Changes

  + Do not break inline elements such as `{i blah}` in docstrings (ocaml-ppx/ocamlformat#1346, @jberdine)

  + Distinguish hash-getter from hash-comparison infix operators. Operators of the form `#**#` or `#**.` where `**` can be 0 or more operator chars are considered getter operators and are not surrounded by spaces, as opposed to regular infix operators (ocaml-ppx/ocamlformat#1376, @gpetiot)

  + Type constraint on return type of functions is now always printed before the function body (ocaml-ppx/ocamlformat#1381, ocaml-ppx/ocamlformat#1397, @gpetiot)

#### Bug fixes

  + Restore previous functionality for pre-post extension points (ocaml-ppx/ocamlformat#1342, @jberdine)

  + Fix extra break before `function` body of a `fun` (ocaml-ppx/ocamlformat#1343, @jberdine)
    Indent further args of anonymous functions (ocaml-ppx/ocamlformat#1440, @gpetiot)

  + Do not clear the emacs `*compilation*` buffer on successful reformat (ocaml-ppx/ocamlformat#1350, @jberdine)

  + Fix disabling with attributes on OCaml < 4.08 (ocaml-ppx/ocamlformat#1322, @emillon)

  + Preserve unwrapped comments by not adding artificial breaks when `wrap-comments=false` and `ocp-indent-compat=true` are set to avoid interfering with ocp-indent indentation. (ocaml-ppx/ocamlformat#1352, @gpetiot)

  + Break long literal strings at the margin (ocaml-ppx/ocamlformat#1367, @gpetiot)

  + Break after a multiline argument in an argument list (ocaml-ppx/ocamlformat#1360, @gpetiot)

  + Remove unnecessary parens around object (ocaml-ppx/ocamlformat#1379, @gpetiot)

  + Fix placement of comments on constants (ocaml-ppx/ocamlformat#1383, @gpetiot)

  + Do not escape arguments of some Odoc tags (ocaml-ppx/ocamlformat#1391, 1408, @gpetiot, @Julow)
    The characters `[]{}` must not be escaped in the arguments of `@raise`, `@author`, `@version` and others.

  + Fix missing open line between multi-line let-binding with poly-typexpr (ocaml-ppx/ocamlformat#1372, @jberdine)

  + Remove trailing space after expression when followed by an attribute and break before attributes attached to multi-line phrases (ocaml-ppx/ocamlformat#1382, @gpetiot)

  + Do not add a space to minimal comments `(* *)`, `(** *)` and `(*$ *)` (ocaml-ppx/ocamlformat#1407, @gpetiot)

  + Fix attributes position in labelled arguments type (ocaml-ppx/ocamlformat#1434, @gpetiot)

  + Add missing parens around type annotation in anonymous function (ocaml-ppx/ocamlformat#1433, @gpetiot)

  + Fix alignment of 'then' keyword in parenthesised expression (ocaml-ppx/ocamlformat#1421, @gpetiot)

#### New features

  + Support quoted extensions (added in ocaml 4.11) (ocaml-ppx/ocamlformat#1405, @gpetiot)

  + Recognise eliom file extensions (ocaml-ppx/ocamlformat#1430, @jrochel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Return types on anonymous functions

3 participants