diff --git a/CHANGELOG.md b/CHANGELOG.md index 12757619fe..fba92ae26f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/build_tests/super_errors/expected/component_missing_prop_test.res.expected b/jscomp/build_tests/super_errors/expected/component_missing_prop_test.res.expected new file mode 100644 index 0000000000..a0a1ebed92 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/component_missing_prop_test.res.expected @@ -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? \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/wrong_name_component_prop.res.expected b/jscomp/build_tests/super_errors/expected/wrong_name_component_prop.res.expected new file mode 100644 index 0000000000..af78b82342 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/wrong_name_component_prop.res.expected @@ -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, +> \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/wrong_name_record_field.res.expected b/jscomp/build_tests/super_errors/expected/wrong_name_record_field.res.expected new file mode 100644 index 0000000000..ab11b80871 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/wrong_name_record_field.res.expected @@ -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 \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/component_missing_prop_test.res b/jscomp/build_tests/super_errors/fixtures/component_missing_prop_test.res new file mode 100644 index 0000000000..2f75f619fa --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/component_missing_prop_test.res @@ -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"} +} diff --git a/jscomp/build_tests/super_errors/fixtures/wrong_name_component_prop.res b/jscomp/build_tests/super_errors/fixtures/wrong_name_component_prop.res new file mode 100644 index 0000000000..2028c2e6b2 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/wrong_name_component_prop.res @@ -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"}) diff --git a/jscomp/build_tests/super_errors/fixtures/wrong_name_record_field.res b/jscomp/build_tests/super_errors/fixtures/wrong_name_record_field.res new file mode 100644 index 0000000000..7ebbbe284c --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/wrong_name_record_field.res @@ -0,0 +1,5 @@ +type d = {z: int} + +let ff: d = { + zz: 123, +} diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index ff86952cd6..3573e7819a 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -3886,12 +3886,16 @@ let report_error env ppf = function name Printtyp.path p; end else begin - fprintf ppf "@[@[<2>%s type@ @{%a@}@]@ " - eorp type_expr ty; + fprintf ppf "@["; - fprintf ppf "The %s @{%s@} does not belong to type @{%a@}@]" + fprintf ppf "@[<2>The %s @{%s@} does not belong to type @{%a@}@]@,@," (label_of_kind kind) name (*kind*) Printtyp.path p; + + fprintf ppf "@[<2>%s type@ @{%a@}@]" + eorp type_expr ty; + + fprintf ppf "@]"; end; spellcheck ppf name valid_names; | Name_type_mismatch (kind, lid, tp, tpl) ->