Skip to content

Flip order of error message for wrong name #6336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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