Skip to content

Commit e3bc40d

Browse files
authored
Flip order of error message for wrong name (#6336)
* flip order of error message for wrong name * cleanup * changelog
1 parent 87d7869 commit e3bc40d

8 files changed

+100
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#### :nail_care: Polish
2424
- Conditionally print error message about record with missing label potentially being a component. https://github.com/rescript-lang/rescript-compiler/pull/6337
25+
- Put definition in the bottom and the actual error at the top when reporting errors for supplying fields etc with the wrong name. https://github.com/rescript-lang/rescript-compiler/pull/6336
2526

2627
# 11.0.0-beta.4
2728

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/component_missing_prop_test.res:5:35-39
4+
5+
3 │ type props<'name> = {name: 'name}
6+
4 │
7+
5 │ let make = (): props<'name> => {nname: "hello"}
8+
6 │ }
9+
7 │
10+
11+
This record expression is expected to have type 'test
12+
The field nname does not belong to type props
13+
Hint: Did you mean name?
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/wrong_name_component_prop.res:32:28-38
4+
5+
30 │ }
6+
31 │
7+
32 │ let dddd = Component.make({nonExistant: "hello"})
8+
33 │
9+
10+
The field nonExistant does not belong to type Component.props
11+
12+
This record expression is expected to have type
13+
Component.props<
14+
string,
15+
string,
16+
string,
17+
string,
18+
string,
19+
string,
20+
string,
21+
string,
22+
string,
23+
>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/wrong_name_record_field.res:4:3-4
4+
5+
2 │
6+
3 │ let ff: d = {
7+
4 │ zz: 123,
8+
5 │ }
9+
6 │
10+
11+
The field zz does not belong to type d
12+
13+
This record expression is expected to have type d
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Since the React transform isn't active in the tests, mimic what the transform outputs.
2+
module Component = {
3+
type props<'name> = {name: 'name}
4+
5+
let make = (): props<'name> => {nname: "hello"}
6+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module SomeComplicatedModuleStructure = {
2+
module NestedModuleHere = {
3+
type t = string
4+
}
5+
}
6+
7+
module Component = {
8+
type props<'name, 'second, 'third, 'fourth, 'fifth, 'sixth, 'seventh, 'eight, 'ninth> = {
9+
name: 'name,
10+
second: 'second,
11+
third: 'third,
12+
fourth: 'fourth,
13+
fifth: 'fifth,
14+
sixth: 'sixth,
15+
seventh: 'seventh,
16+
eight: 'eight,
17+
ninth: 'ninth,
18+
}
19+
let make = props => {
20+
props.name ++
21+
props.second ++
22+
props.third ++
23+
props.fourth ++
24+
props.fifth ++
25+
props.sixth ++
26+
props.seventh ++
27+
props.eight ++
28+
props.ninth
29+
}
30+
}
31+
32+
let dddd = Component.make({nonExistant: "hello"})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type d = {z: int}
2+
3+
let ff: d = {
4+
zz: 123,
5+
}

jscomp/ml/typecore.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,12 +3886,16 @@ let report_error env ppf = function
38863886
name
38873887
Printtyp.path p;
38883888
end else begin
3889-
fprintf ppf "@[@[<2>%s type@ @{<info>%a@}@]@ "
3890-
eorp type_expr ty;
3889+
fprintf ppf "@[<v>";
38913890
3892-
fprintf ppf "The %s @{<error>%s@} does not belong to type @{<info>%a@}@]"
3891+
fprintf ppf "@[<2>The %s @{<error>%s@} does not belong to type @{<info>%a@}@]@,@,"
38933892
(label_of_kind kind)
38943893
name (*kind*) Printtyp.path p;
3894+
3895+
fprintf ppf "@[<2>%s type@ @{<info>%a@}@]"
3896+
eorp type_expr ty;
3897+
3898+
fprintf ppf "@]";
38953899
end;
38963900
spellcheck ppf name valid_names;
38973901
| Name_type_mismatch (kind, lid, tp, tpl) ->

0 commit comments

Comments
 (0)