Skip to content

Commit 63fd342

Browse files
authored
Clean up Super_error (#6199)
* add tests * error message with loc of repeated definition * changelog * clean up * clean up super_error * use Location.print_loc * move some tests from ounit to super_errors * changelog * remove unused ounit tests * changelog * changelog
1 parent f2d5c80 commit 63fd342

38 files changed

+618
-944
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#### :boom: Breaking Change
2525

2626
- Parse `assert` as a regular function. `assert` is no longer a unary expression. Example: before `assert 1 == 2` is parsed as `(assert 1) == 2`, now it is parsed as `assert(1 == 2)`. https://github.com/rescript-lang/rescript-compiler/pull/6180
27+
- `-bs-super-errors` flag has been removed along with Super_errors. https://github.com/rescript-lang/rescript-compiler/pull/6199
2728

2829
#### :bug: Bug Fix
2930

@@ -32,6 +33,11 @@
3233
- Add error messages for dangling doc comments/attributes and mutable in record type definition. https://github.com/rescript-lang/rescript-compiler/pull/6206
3334
- Fix issue with overlapping array and object in untagged variants https://github.com/rescript-lang/rescript-compiler/pull/6219
3435

36+
#### :nail_care: Polish
37+
38+
- Add location information to duplicate type definition error messages. https://github.com/rescript-lang/rescript-compiler/pull/6199
39+
- Replace normal module errors with Super_error module, and clean up Super_error. https://github.com/rescript-lang/rescript-compiler/pull/6199
40+
3541
# 11.0.0-alpha.4
3642

3743
#### :rocket: Main New Feature

jscomp/bsc/dune

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
(public_name bsc)
99
(flags
1010
(:standard -w +a-4-9-30-40-41-42-48-70))
11-
(libraries common core depends gentype js_parser syntax super_errors
12-
outcome_printer))
11+
(libraries common core depends gentype js_parser syntax outcome_printer))

jscomp/bsc/rescript_compiler_main.ml

+1-7
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ let setup_compiler_printer (syntax_kind : [ syntax_kind | `default])=
2525
| `default -> ()
2626
| #syntax_kind as k -> Config.syntax_kind := k);
2727
let syntax_kind = !Config.syntax_kind in
28-
if syntax_kind = `rescript then begin
29-
Lazy.force Super_main.setup;
28+
if syntax_kind = `rescript then begin
3029
Lazy.force Res_outcome_printer.setup
3130
end
3231

@@ -206,7 +205,6 @@ let print_version_string () =
206205

207206
let [@inline] set s : Bsc_args.spec = Unit (Unit_set s)
208207
let [@inline] clear s : Bsc_args.spec = Unit (Unit_clear s)
209-
let [@inline] unit_lazy s : Bsc_args.spec = Unit(Unit_lazy s)
210208
let [@inline] string_call s : Bsc_args.spec =
211209
String (String_call s)
212210
let [@inline] string_optional_set s : Bsc_args.spec =
@@ -294,10 +292,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
294292

295293
(******************************************************************************)
296294

297-
298-
"-bs-super-errors", unit_lazy Super_main.setup,
299-
"*internal* Better error message combined with other tools ";
300-
301295
"-unboxed-types", set Clflags.unboxed_types,
302296
"*internal* Unannotated unboxable types will be unboxed";
303297

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/repeated_def_extension_constr.res:3:6
4+
5+
1 │ type a = ..
6+
2 │
7+
3 │ type a
8+
4 │
9+
10+
Multiple definition of the type name a
11+
at /.../fixtures/repeated_def_extension_constr.res:1:6
12+
Names must be unique in a given structure or signature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/repeated_def_module_types.res:3:13
4+
5+
1 │ module type M = {}
6+
2 │
7+
3 │ module type M = {}
8+
4 │
9+
10+
Multiple definition of the module type name M
11+
at /.../fixtures/repeated_def_module_types.res:1:13
12+
Names must be unique in a given structure or signature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/repeated_def_modules.res:3:8
4+
5+
1 │ module M = {}
6+
2 │
7+
3 │ module M = {}
8+
4 │
9+
10+
Multiple definition of the module name M
11+
at /.../fixtures/repeated_def_modules.res:1:8
12+
Names must be unique in a given structure or signature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/repeated_def_types.res:3:6
4+
5+
1 │ type a
6+
2 │
7+
3 │ type a
8+
4 │
9+
10+
Multiple definition of the type name a
11+
at /.../fixtures/repeated_def_types.res:1:6
12+
Names must be unique in a given structure or signature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/type2.res:6:11-13
4+
5+
4 │ let () = {
6+
5 │ push(a, 3)->ignore
7+
6 │ push(a, "3")->ignore
8+
7 │ }
9+
8 │
10+
11+
This has type: string
12+
Somewhere wanted: int
13+
14+
You can convert string to int with Belt.Int.fromString.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/type3.res:1:5
4+
5+
1 │ let u = []
6+
2 │
7+
8+
This expression's type contains type variables that cannot be generalized:
9+
array<'_weak1>
10+
11+
This happens when the type system senses there's a mutation/side-effect,
12+
in combination with a polymorphic value.
13+
Using or annotating that value usually solves it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type a = ..
2+
3+
type a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module type M = {}
2+
3+
module type M = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module M = {}
2+
3+
module M = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type a
2+
3+
type a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@send external push: (array<'a>, 'a) => unit = "push"
2+
3+
let a = []
4+
let () = {
5+
push(a, 3)->ignore
6+
push(a, "3")->ignore
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let u = []

jscomp/build_tests/super_errors/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let atLeastOneTaskFailed = false
2727

2828
fixtures.forEach(fileName => {
2929
const fullFilePath = path.join(__dirname, 'fixtures', fileName)
30-
const command = `${prefix} -color always -bs-super-errors ${fullFilePath}`
30+
const command = `${prefix} -color always ${fullFilePath}`
3131
console.log(`running ${command}`)
3232
child_process.exec(command, (err, stdout, stderr) => {
3333
doneTasksCount++

jscomp/gentype_tests/typescript-react-example/bsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"exportInterfaces": false
1616
},
1717
"name": "sample-typescript-app",
18-
"bsc-flags": ["-bs-super-errors"],
18+
"bsc-flags": [],
1919
"jsx": { "version": 3 },
2020
"bs-dependencies": ["@rescript/react"],
2121
"sources": [
File renamed without changes.

jscomp/ml/env.ml

+30-20
Original file line numberDiff line numberDiff line change
@@ -2276,32 +2276,42 @@ let env_of_only_summary env_from_summary env =
22762276

22772277
open Format
22782278

2279+
(* taken from https://github.com/rescript-lang/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/env.ml#L1842 *)
2280+
(* modified branches are commented *)
22792281
let report_error ppf = function
2280-
| Illegal_renaming(modname, ps_name, filename) -> fprintf ppf
2281-
"Wrong file naming: %a@ contains the compiled interface for @ \
2282-
%s when %s was expected"
2283-
Location.print_filename filename ps_name modname
2284-
| Inconsistent_import(name, source1, source2) -> fprintf ppf
2282+
| Illegal_renaming(name, modname, _filename) ->
2283+
(* modified *)
2284+
fprintf ppf
2285+
"@[You referred to the module %s, but we've found one called %s instead.@ \
2286+
Is the name's casing right?@]"
2287+
name modname
2288+
| Inconsistent_import(name, source1, source2) ->
2289+
(* modified *)
2290+
fprintf ppf "@[<v>\
2291+
@[@{<info>It's possible that your build is stale.@}@ Try to clean the artifacts and build again?@]@,@,\
2292+
@[@{<info>Here's the original error message@}@]@,\
2293+
@]";
2294+
fprintf ppf
22852295
"@[<hov>The files %a@ and %a@ \
2286-
make inconsistent assumptions@ over interface %s@]"
2296+
make inconsistent assumptions@ over interface %s@]"
22872297
Location.print_filename source1 Location.print_filename source2 name
22882298
| Need_recursive_types(import, export) ->
2289-
fprintf ppf
2290-
"@[<hov>Unit %s imports from %s, which uses recursive types.@ %s@]"
2291-
export import "The compilation flag -rectypes is required"
2299+
fprintf ppf
2300+
"@[<hov>Unit %s imports from %s, which uses recursive types.@ %s@]"
2301+
export import "The compilation flag -rectypes is required"
22922302
| Missing_module(_, path1, path2) ->
2293-
fprintf ppf "@[@[<hov>";
2294-
if Path.same path1 path2 then
2295-
fprintf ppf "Internal path@ %s@ is dangling." (Path.name path1)
2296-
else
2297-
fprintf ppf "Internal path@ %s@ expands to@ %s@ which is dangling."
2298-
(Path.name path1) (Path.name path2);
2299-
fprintf ppf "@]@ @[%s@ %s@ %s.@]@]"
2300-
"The compiled interface for module" (Ident.name (Path.head path2))
2301-
"was not found"
2303+
fprintf ppf "@[@[<hov>";
2304+
if Path.same path1 path2 then
2305+
fprintf ppf "Internal path@ %s@ is dangling." (Path.name path1)
2306+
else
2307+
fprintf ppf "Internal path@ %s@ expands to@ %s@ which is dangling."
2308+
(Path.name path1) (Path.name path2);
2309+
fprintf ppf "@]@ @[%s@ %s@ %s.@]@]"
2310+
"The compiled interface for module" (Ident.name (Path.head path2))
2311+
"was not found"
23022312
| Illegal_value_name(_loc, name) ->
2303-
fprintf ppf "'%s' is not a valid value identifier."
2304-
name
2313+
fprintf ppf "'%s' is not a valid value identifier."
2314+
name
23052315

23062316
let () =
23072317
Location.register_error_of_exn

jscomp/ml/lexer.mll

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ let report_error ppf = function
254254
| Unterminated_string_in_comment (_, loc) ->
255255
fprintf ppf "This comment contains an unterminated string literal@.\
256256
%aString literal begins here"
257-
Location.print_error loc
257+
(Location.print_error "") loc
258258
| Keyword_as_label kwd ->
259259
fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd
260260
| Invalid_literal s ->

0 commit comments

Comments
 (0)