Skip to content

Commit

Permalink
Merge 98fd547 into c9e5bf2
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglou committed Mar 15, 2018
2 parents c9e5bf2 + 98fd547 commit ce507be
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion jscomp/Makefile
Expand Up @@ -365,7 +365,7 @@ BSB_SRCS= bsb_config\
oCamlRes\
bsb_templates\
bsb_theme_init
SUPER_ERRORS_SRCS=super_reason_react super_misc super_warnings super_location super_env super_pparse super_typecore super_typemod super_typetexp super_main
SUPER_ERRORS_SRCS=super_reason_flag super_reason_react super_misc super_warnings super_location super_env super_pparse super_typecore super_typemod super_typetexp super_main
REASON_OUTCOME_PRINTER_SRCS= outcome_printer_ns tweaked_reason_oprint reason_outcome_printer_main

BSB_CMXS=$(addprefix bsb/, $(addsuffix .cmx, $(BSB_SRCS)))
Expand Down
5 changes: 4 additions & 1 deletion jscomp/core/js_main.ml
Expand Up @@ -101,7 +101,10 @@ let buckle_script_flags : (string * Arg.spec * string) list =
)
::
("-bs-re-out",
Arg.Unit Reason_outcome_printer_main.setup,
Arg.Unit (fun () ->
Reason_outcome_printer_main.setup ();
Super_reason_flag.using_reason_syntax := true
),
" Print compiler output in Reason syntax"
)
::
Expand Down
13 changes: 12 additions & 1 deletion jscomp/super_errors/README.md
@@ -1,11 +1,22 @@
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/BuckleScript/ocaml/tree/master). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point, and `super_reason_react`, our special handling of [ReasonReact](https://reasonml.github.io/reason-react/) errors.
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/BuckleScript/ocaml/tree/master). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point, `super_reason_react`, our special handling of [ReasonReact](https://reasonml.github.io/reason-react/) errors, and `super_reason_flag`.

Feel free to submit new ones or tweak existing messages in these files! They also have more precise comments in them that tells you how they work.

### Develop

Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for the build & testing setup.

### Reason-specific Tweaks

Super-errors caters to both OCaml and Reason files' errors. Some logic are specific to each:

- The error type/value output syntax from the compiler
- Some error messages' wording and solutions

The first one is controlled by the `-bs-re-out` flag in the compiler (see `js_main.ml`). This flag is passed to the compiler by the build system's rule for compiling Reason files. The flag triggers the setup of the Reason outcome printer (`Reason_outcome_printer_main.ml`), which overrides OCaml's error printing logic to output in Reason syntax instead of the default OCaml syntax. So really, even though this process seems to be super-errors-specific, it's not.

The second one is controlled by `super_reason_flag`. Some error messages' recommended fix are OCaml/Reason-specific, so they need to know whether for which syntax we're outputting the message. The flag `Super_reason_flag.using_reason_syntax` indicates this. It's set inside `-bs-re-out` too.

#### SuperErrors-specific Tests Flow

Note: currently you can't test things with external libraries (e.g. ReasonReact).
Expand Down
1 change: 1 addition & 0 deletions jscomp/super_errors/super_reason_flag.ml
@@ -0,0 +1 @@
let using_reason_syntax = ref false
23 changes: 16 additions & 7 deletions jscomp/super_errors/super_typecore.ml
Expand Up @@ -234,13 +234,22 @@ let report_error env ppf = function
_
)
->
fprintf
ppf
"@[<v>This is an uncurried BuckleScript function. @{<info>It must be applied with a dot@}.@,@,\
Like this: @{<info>foo(. a, b)@}@,\
Not like this: @{<dim>foo(a, b)@}@,@,\
This guarantees that your function is fully applied. More info here:@,\
https://bucklescript.github.io/docs/en/function.html#solution-guaranteed-uncurrying@]"
if !Super_reason_flag.using_reason_syntax then
fprintf
ppf
"@[<v>This is an uncurried BuckleScript function. @{<info>It must be applied with a dot@}.@,@,\
Like this: @{<info>foo(. a, b)@}@,\
Not like this: @{<dim>foo(a, b)@}@,@,\
This guarantees that your function is fully applied. More info here:@,\
https://bucklescript.github.io/docs/en/function.html#solution-guaranteed-uncurrying@]"
else
fprintf
ppf
"@[<v>This is an uncurried BuckleScript function. @{<info>It must be applied with [@@bs]@}.@,@,\
Like this: @{<info>foo 1 2 [@bs]@}@,\
Not like this: @{<dim>foo 1 2@}@,@,\
This guarantees that your function is fully applied. More info here:@,\
https://bucklescript.github.io/docs/en/function.html#solution-guaranteed-uncurrying@]"
| _ ->
fprintf ppf "@[<v>@[<2>This expression has type@ %a@]@ %s@]"
type_expr typ
Expand Down
5 changes: 4 additions & 1 deletion jscomp/super_errors/super_warnings.ml
Expand Up @@ -19,6 +19,9 @@ let message (warning : Warnings.t) =
"Note: some build systems might e.g. turn kebab-case into CamelCase module, which is why this isn't a hard error."
| Statement_type -> "This expression returns a value, but you're not doing anything with it. If this is on purpose, put `|> ignore` at the end."
| Useless_record_with ->
"All the fields are already explicitly listed in this record. You can remove the `...` spread."
if !Super_reason_flag.using_reason_syntax then
"All the fields are already explicitly listed in this record. You can remove the `...` spread."
else
"All the fields are explicitly listed in this record. You can remove the `with` clause."
| _ -> Warnings.message warning
;;

0 comments on commit ce507be

Please sign in to comment.