Skip to content

Commit f5f1073

Browse files
committed
add config.syntax_kind, remove super_warnings
1 parent fb26388 commit f5f1073

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

utils/config.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ val version: string
2121
val standard_library: string
2222
(* The directory containing the standard libraries *)
2323

24+
val syntax_kind : [ `ml | `reason | `rescript ] ref
25+
2426
val bs_only : bool ref
2527

2628
val standard_runtime: string

utils/config.mlp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let standard_library =
3434
#end
3535
standard_library_default
3636
let bs_only = ref false
37+
let syntax_kind = ref `ml
3738
let standard_runtime = "%%BYTERUN%%"
3839
let ccomp_type = "%%CCOMPTYPE%%"
3940
let c_compiler = "%%CC%%"

utils/warnings.ml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ let backup () = !current
256256
let restore x = current := x
257257

258258
let is_active x = not !disabled && (!current).active.(number x);;
259-
#if true then
260-
let is_error = is_active
261-
#else
262-
let is_error x = not !disabled && (!current).error.(number x);;
263-
#end
259+
260+
let is_error =
261+
if !Config.bs_only then is_active else
262+
fun x -> not !disabled && (!current).error.(number x)
263+
264264

265265
let mk_lazy f =
266266
let state = backup () in
@@ -376,15 +376,27 @@ let message = function
376376
("the following methods are overridden by the class"
377377
:: cname :: ":\n " :: slist)
378378
| Method_override [] -> assert false
379+
#if true then
380+
| Partial_match "" ->
381+
"You forgot to handle a possible case here, though we don't have more information on the value."
382+
| Partial_match s ->
383+
"You forgot to handle a possible case here, for example: \n " ^ s
384+
#else
379385
| Partial_match "" -> "this pattern-matching is not exhaustive."
380386
| Partial_match s ->
381387
"this pattern-matching is not exhaustive.\n\
382388
Here is an example of a case that is not matched:\n" ^ s
389+
#end
383390
| Non_closed_record_pattern s ->
384391
"the following labels are not bound in this record pattern:\n" ^ s ^
385392
"\nEither bind these labels explicitly or add '; _' to the pattern."
393+
#if true then
394+
| Statement_type ->
395+
"This expression returns a value, but you're not doing anything with it. If this is on purpose, wrap it with `ignore`."
396+
#else
386397
| Statement_type ->
387398
"this expression should have type unit."
399+
#end
388400
| Unused_match -> "this match case is unused."
389401
| Unused_pat -> "this sub-pattern is unused."
390402
| Instance_variable_override [lab] ->
@@ -400,7 +412,17 @@ let message = function
400412
| Implicit_public_methods l ->
401413
"the following private methods were made public implicitly:\n "
402414
^ String.concat " " l ^ "."
415+
#if true then
416+
| Unerasable_optional_argument ->
417+
String.concat ""
418+
["This optional parameter in final position will, in practice, not be optional.\n";
419+
" Reorder the parameters so that at least one non-optional one is in final position or, if all parameters are optional, insert a final ().\n\n";
420+
" Explanation: If the final parameter is optional, it'd be unclear whether a function application that omits it should be considered fully applied, or partially applied. Imagine writing `let title = display(\"hello!\")`, only to realize `title` isn't your desired result, but a curried call that takes a final optional argument, e.g. `~showDate`.\n\n";
421+
" Formal rule: an optional argument is considered intentionally omitted when the 1st positional (i.e. neither labeled nor optional) argument defined after it is passed in."
422+
]
423+
#else
403424
| Unerasable_optional_argument -> "this optional argument cannot be erased."
425+
#end
404426
| Undeclared_virtual_method m -> "the virtual method "^m^" is not declared."
405427
| Not_principal s -> s^" is not principal."
406428
| Without_principality s -> s^" without principality."
@@ -409,10 +431,21 @@ let message = function
409431
"this statement never returns (or has an unsound type.)"
410432
| Preprocessor s -> s
411433
| Useless_record_with ->
434+
begin match !Config.syntax_kind with
435+
| `ml ->
412436
"all the fields are explicitly listed in this record:\n\
413437
the 'with' clause is useless."
438+
| `reason | `rescript ->
439+
"All the fields are already explicitly listed in this record. You can remove the `...` spread."
440+
end
441+
#if true then
414442
| Bad_module_name (modname) ->
443+
"This file's name is potentially invalid. The build systems conventionally turn a file name into a module name by upper-casing the first letter. " ^ modname ^ " isn't a valid module name.\n" ^
444+
"Note: some build systems might e.g. turn kebab-case into CamelCase module, which is why this isn't a hard error."
445+
#else
446+
| Bad_module_name (modname) ->
415447
"bad source file name: \"" ^ modname ^ "\" is not a valid module name."
448+
#end
416449
| All_clauses_guarded ->
417450
"this pattern-matching is not exhaustive.\n\
418451
All clauses in this pattern-matching are guarded."
@@ -616,17 +649,7 @@ let report w =
616649
}
617650
;;
618651

619-
#if true then
620-
let super_report message w =
621-
match is_active w with
622-
| false -> `Inactive
623-
| true ->
624-
if is_error w then incr nerrors;
625-
`Active { number = number w; message = message w; is_error = is_error w;
626-
sub_locs = sub_locs w;
627-
}
628-
;;
629-
#end
652+
630653
exception Errors;;
631654

632655
let reset_fatal () =

utils/warnings.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,4 @@ val mk_lazy: (unit -> 'a) -> 'a Lazy.t
137137
val nerrors : int ref
138138
val message : t -> string
139139
val number: t -> int
140-
val super_report :
141-
(t -> string) ->
142-
t -> [ `Active of reporting_information | `Inactive ]
143140
#end

0 commit comments

Comments
 (0)