From 4d7be3dca68fbb2d2cd2669af8ac45f9a2d85a8a Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 29 May 2025 21:42:52 +0200 Subject: [PATCH 1/3] Don't use ghost location in jsx transform --- compiler/syntax/src/jsx_v4.ml | 5 ++-- .../wrong_type_prop_punning.res.expected | 12 ++++++++++ .../fixtures/wrong_type_prop_punning.res | 23 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/build_tests/super_errors/expected/wrong_type_prop_punning.res.expected create mode 100644 tests/build_tests/super_errors/fixtures/wrong_type_prop_punning.res diff --git a/compiler/syntax/src/jsx_v4.ml b/compiler/syntax/src/jsx_v4.ml index a94cb7466e..32fd92155b 100644 --- a/compiler/syntax/src/jsx_v4.ml +++ b/compiler/syntax/src/jsx_v4.ml @@ -1131,7 +1131,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props) { loc_start = first_item.loc_start; loc_end = last_item.loc_end; - loc_ghost = true; + loc_ghost = false; } in (* key should be filtered out *) @@ -1156,7 +1156,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props) | JSXPropPunning (is_optional, name) -> { lid = {txt = Lident name.txt; loc = name.loc}; - x = Exp.ident {txt = Lident name.txt; loc = name.loc}; + x = Exp.ident ~loc:name.loc {txt = Lident name.txt; loc = name.loc}; opt = is_optional; } | JSXPropValue (name, is_optional, value) -> @@ -1303,7 +1303,6 @@ let expr ~(config : Jsx_common.jsx_config) mapper expression = pexp_loc = loc; pexp_attributes = attrs; } -> ( - let loc = {loc with loc_ghost = true} in match jsx_element with | Jsx_fragment {jsx_fragment_children = children} -> let fragment = diff --git a/tests/build_tests/super_errors/expected/wrong_type_prop_punning.res.expected b/tests/build_tests/super_errors/expected/wrong_type_prop_punning.res.expected new file mode 100644 index 0000000000..897bf7dce2 --- /dev/null +++ b/tests/build_tests/super_errors/expected/wrong_type_prop_punning.res.expected @@ -0,0 +1,12 @@ + + We've found a bug for you! + /.../fixtures/wrong_type_prop_punning.res:21:13-20 + + 19 │ @react.component + 20 │ let make = (~someProp: array) => { + 21 │ + 22 │ } + 23 │ } + + This has type: array + But it's expected to have type: float \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/wrong_type_prop_punning.res b/tests/build_tests/super_errors/fixtures/wrong_type_prop_punning.res new file mode 100644 index 0000000000..797539e172 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/wrong_type_prop_punning.res @@ -0,0 +1,23 @@ +module React = { + type element = Jsx.element + @val external null: element = "null" + type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return> + type component<'props> = Jsx.component<'props> + external component: componentLike<'props, element> => component<'props> = "%identity" + @module("react/jsx-runtime") + external jsx: (component<'props>, 'props) => element = "jsx" +} + +module Level2 = { + @react.component + let make = (~someProp: float) => { + React.null + } +} + +module Level1 = { + @react.component + let make = (~someProp: array) => { + + } +} From a45a12cd3140fcd48321fe34c14f9f1ea61e715d Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 29 May 2025 21:43:55 +0200 Subject: [PATCH 2/3] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762221b4a2..cdce5e4bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Treat `throw` like `raise` in analysis. https://github.com/rescript-lang/rescript/pull/7521 - Fix `index out of bounds` exception thrown in rare cases by `rescript-editor-analysis.exe codeAction` command. https://github.com/rescript-lang/rescript/pull/7523 - Don't produce duplicate type definitions for recursive types on hover. https://github.com/rescript-lang/rescript/pull/7524 +- Prop punning when types don't match results in I/O error: _none_: No such file or directory. https://github.com/rescript-lang/rescript/pull/7533 #### :nail_care: Polish From 5ae3164ae9ec56bfcc341cb81529ebc9c83d4a42 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 29 May 2025 21:48:56 +0200 Subject: [PATCH 3/3] Update analysis snapshot --- tests/analysis_tests/tests/src/expected/Fragment.res.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/Fragment.res.txt b/tests/analysis_tests/tests/src/expected/Fragment.res.txt index 2dba106a7d..689d63155e 100644 --- a/tests/analysis_tests/tests/src/expected/Fragment.res.txt +++ b/tests/analysis_tests/tests/src/expected/Fragment.res.txt @@ -2,9 +2,5 @@ Hover src/Fragment.res 6:19 {"contents": {"kind": "markdown", "value": "```rescript\nReact.component>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Fragment.res%22%2C1%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"}} Hover src/Fragment.res 9:56 -Nothing at that position. Now trying to use completion. -posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:9->9:70] -posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:12->9:66] -JSX 9:26] > _children:9:29 -null +{"contents": {"kind": "markdown", "value": "```rescript\nReact.component\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.fragmentProps = {children?: element}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C41%2C0%5D)\n"}}