Skip to content

Commit

Permalink
Flip order of error message for wrong name (#6336)
Browse files Browse the repository at this point in the history
* flip order of error message for wrong name

* cleanup

* changelog
  • Loading branch information
zth authored Aug 7, 2023
1 parent 87d7869 commit e3bc40d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#### :nail_care: Polish
- Conditionally print error message about record with missing label potentially being a component. https://github.com/rescript-lang/rescript-compiler/pull/6337
- 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

# 11.0.0-beta.4

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

We've found a bug for you!
/.../fixtures/component_missing_prop_test.res:5:35-39

3 │ type props<'name> = {name: 'name}
4 │
5 │ let make = (): props<'name> => {nname: "hello"}
6 │ }
7 │

This record expression is expected to have type 'test
The field nname does not belong to type props
Hint: Did you mean name?
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

We've found a bug for you!
/.../fixtures/wrong_name_component_prop.res:32:28-38

30 │ }
31 │
32 │ let dddd = Component.make({nonExistant: "hello"})
33 │

The field nonExistant does not belong to type Component.props

This record expression is expected to have type
Component.props<
string,
string,
string,
string,
string,
string,
string,
string,
string,
>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

We've found a bug for you!
/.../fixtures/wrong_name_record_field.res:4:3-4

2 │
3 │ let ff: d = {
4 │ zz: 123,
5 │ }
6 │

The field zz does not belong to type d

This record expression is expected to have type d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Since the React transform isn't active in the tests, mimic what the transform outputs.
module Component = {
type props<'name> = {name: 'name}

let make = (): props<'name> => {nname: "hello"}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module SomeComplicatedModuleStructure = {
module NestedModuleHere = {
type t = string
}
}

module Component = {
type props<'name, 'second, 'third, 'fourth, 'fifth, 'sixth, 'seventh, 'eight, 'ninth> = {
name: 'name,
second: 'second,
third: 'third,
fourth: 'fourth,
fifth: 'fifth,
sixth: 'sixth,
seventh: 'seventh,
eight: 'eight,
ninth: 'ninth,
}
let make = props => {
props.name ++
props.second ++
props.third ++
props.fourth ++
props.fifth ++
props.sixth ++
props.seventh ++
props.eight ++
props.ninth
}
}

let dddd = Component.make({nonExistant: "hello"})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type d = {z: int}

let ff: d = {
zz: 123,
}
10 changes: 7 additions & 3 deletions jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3886,12 +3886,16 @@ let report_error env ppf = function
name
Printtyp.path p;
end else begin
fprintf ppf "@[@[<2>%s type@ @{<info>%a@}@]@ "
eorp type_expr ty;
fprintf ppf "@[<v>";
fprintf ppf "The %s @{<error>%s@} does not belong to type @{<info>%a@}@]"
fprintf ppf "@[<2>The %s @{<error>%s@} does not belong to type @{<info>%a@}@]@,@,"
(label_of_kind kind)
name (*kind*) Printtyp.path p;
fprintf ppf "@[<2>%s type@ @{<info>%a@}@]"
eorp type_expr ty;
fprintf ppf "@]";
end;
spellcheck ppf name valid_names;
| Name_type_mismatch (kind, lid, tp, tpl) ->
Expand Down

0 comments on commit e3bc40d

Please sign in to comment.