diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c5c3e15ce..e1be0e46bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ #### :nail_care: Polish +- In type errors, recommend stdlib over Belt functions for converting between float/int/string. https://github.com/rescript-lang/rescript/pull/7453 - Make `Jsx.element` a private empty record to avoid unnecessary `Primitive_option.some`. https://github.com/rescript-lang/rescript/pull/7450 # 12.0.0-alpha.12 diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index a7ac76a341..dd69ad1ad2 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -676,12 +676,12 @@ let rec bottom_aliases = function let simple_conversions = [ - (("float", "int"), "Belt.Float.toInt"); - (("float", "string"), "Belt.Float.toString"); - (("int", "float"), "Belt.Int.toFloat"); - (("int", "string"), "Belt.Int.toString"); - (("string", "float"), "Belt.Float.fromString"); - (("string", "int"), "Belt.Int.fromString"); + (("float", "int"), "Float.toInt"); + (("float", "string"), "Float.toString"); + (("int", "float"), "Int.toFloat"); + (("int", "string"), "Int.toString"); + (("string", "float"), "Float.fromString"); + (("string", "int"), "Int.fromString"); ] let print_simple_conversion ppf (actual, expected) = diff --git a/tests/build_tests/super_errors/expected/array_item_type_mismatch.res.expected b/tests/build_tests/super_errors/expected/array_item_type_mismatch.res.expected index 54c99ad256..af3c2e059d 100644 --- a/tests/build_tests/super_errors/expected/array_item_type_mismatch.res.expected +++ b/tests/build_tests/super_errors/expected/array_item_type_mismatch.res.expected @@ -14,4 +14,4 @@ - Convert all values in the array to the same type. - Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true) - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/collections.res.expected b/tests/build_tests/super_errors/expected/collections.res.expected index 41b190b6f8..2e83a91635 100644 --- a/tests/build_tests/super_errors/expected/collections.res.expected +++ b/tests/build_tests/super_errors/expected/collections.res.expected @@ -9,4 +9,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/dict_inference.res.expected b/tests/build_tests/super_errors/expected/dict_inference.res.expected index 42f32b879e..d7a4a84f49 100644 --- a/tests/build_tests/super_errors/expected/dict_inference.res.expected +++ b/tests/build_tests/super_errors/expected/dict_inference.res.expected @@ -10,4 +10,4 @@ This has type: string But this function argument is expecting: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/dict_pattern_inference_constrained.res.expected b/tests/build_tests/super_errors/expected/dict_pattern_inference_constrained.res.expected index ce340c0ae9..7263287dfb 100644 --- a/tests/build_tests/super_errors/expected/dict_pattern_inference_constrained.res.expected +++ b/tests/build_tests/super_errors/expected/dict_pattern_inference_constrained.res.expected @@ -14,4 +14,4 @@ The incompatible parts: int vs string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/function_argument_mismatch.res.expected b/tests/build_tests/super_errors/expected/function_argument_mismatch.res.expected index 3905f123f6..50caaf7ca6 100644 --- a/tests/build_tests/super_errors/expected/function_argument_mismatch.res.expected +++ b/tests/build_tests/super_errors/expected/function_argument_mismatch.res.expected @@ -10,4 +10,4 @@ This has type: int But this function argument is expecting: string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/highlighting1.res.expected b/tests/build_tests/super_errors/expected/highlighting1.res.expected index 3e79ccf230..4fd22bb259 100644 --- a/tests/build_tests/super_errors/expected/highlighting1.res.expected +++ b/tests/build_tests/super_errors/expected/highlighting1.res.expected @@ -10,4 +10,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/highlighting2.res.expected b/tests/build_tests/super_errors/expected/highlighting2.res.expected index 3701c234bb..4c7cb77157 100644 --- a/tests/build_tests/super_errors/expected/highlighting2.res.expected +++ b/tests/build_tests/super_errors/expected/highlighting2.res.expected @@ -10,4 +10,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/highlighting3.res.expected b/tests/build_tests/super_errors/expected/highlighting3.res.expected index 7845aa238d..292a9c4902 100644 --- a/tests/build_tests/super_errors/expected/highlighting3.res.expected +++ b/tests/build_tests/super_errors/expected/highlighting3.res.expected @@ -10,4 +10,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/highlighting5.res.expected b/tests/build_tests/super_errors/expected/highlighting5.res.expected index 6e6ab03a30..6062a37b7d 100644 --- a/tests/build_tests/super_errors/expected/highlighting5.res.expected +++ b/tests/build_tests/super_errors/expected/highlighting5.res.expected @@ -10,4 +10,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/if_branch_mismatch.res.expected b/tests/build_tests/super_errors/expected/if_branch_mismatch.res.expected index 714a6f074f..ac887753f2 100644 --- a/tests/build_tests/super_errors/expected/if_branch_mismatch.res.expected +++ b/tests/build_tests/super_errors/expected/if_branch_mismatch.res.expected @@ -13,4 +13,4 @@ if expressions must return the same type in all branches (if, else if, else). - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/inline_types_record_type_params.res.expected b/tests/build_tests/super_errors/expected/inline_types_record_type_params.res.expected index be9fed0456..8a69447541 100644 --- a/tests/build_tests/super_errors/expected/inline_types_record_type_params.res.expected +++ b/tests/build_tests/super_errors/expected/inline_types_record_type_params.res.expected @@ -11,4 +11,4 @@ This has type: int But it's expected to have type: string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/math_operator_constant.res.expected b/tests/build_tests/super_errors/expected/math_operator_constant.res.expected index 741b07af7a..d500a914ab 100644 --- a/tests/build_tests/super_errors/expected/math_operator_constant.res.expected +++ b/tests/build_tests/super_errors/expected/math_operator_constant.res.expected @@ -10,5 +10,5 @@ This has type: float But it's expected to have type: int - You can convert float to int with Belt.Float.toInt. + You can convert float to int with Float.toInt. If this is a literal, try a number without a trailing dot (e.g. 20). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/math_operator_float.res.expected b/tests/build_tests/super_errors/expected/math_operator_float.res.expected index cd0fffa1c1..640e57a500 100644 --- a/tests/build_tests/super_errors/expected/math_operator_float.res.expected +++ b/tests/build_tests/super_errors/expected/math_operator_float.res.expected @@ -16,5 +16,5 @@ - Ensure all values in this calculation has the type float. You can convert between floats and ints via Belt.Float.toInt and Belt.Int.fromFloat. - Change the operator to +, which works on int - You can convert int to float with Belt.Int.toFloat. + You can convert int to float with Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives1.res.expected b/tests/build_tests/super_errors/expected/primitives1.res.expected index cc2946f160..761f341aba 100644 --- a/tests/build_tests/super_errors/expected/primitives1.res.expected +++ b/tests/build_tests/super_errors/expected/primitives1.res.expected @@ -9,5 +9,5 @@ This has type: int But it's expected to have type: float - You can convert int to float with Belt.Int.toFloat. + You can convert int to float with Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives11.res.expected b/tests/build_tests/super_errors/expected/primitives11.res.expected index 6123d58b2c..be16c35ee0 100644 --- a/tests/build_tests/super_errors/expected/primitives11.res.expected +++ b/tests/build_tests/super_errors/expected/primitives11.res.expected @@ -16,4 +16,4 @@ Further expanded: int vs string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives2.res.expected b/tests/build_tests/super_errors/expected/primitives2.res.expected index 29b554f51e..a967be243a 100644 --- a/tests/build_tests/super_errors/expected/primitives2.res.expected +++ b/tests/build_tests/super_errors/expected/primitives2.res.expected @@ -9,4 +9,4 @@ This has type: int But string concatenation is expecting: string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives6.res.expected b/tests/build_tests/super_errors/expected/primitives6.res.expected index 6e46bb560a..cc665fac7b 100644 --- a/tests/build_tests/super_errors/expected/primitives6.res.expected +++ b/tests/build_tests/super_errors/expected/primitives6.res.expected @@ -10,5 +10,5 @@ This has type: int But it's expected to have type: float - You can convert int to float with Belt.Int.toFloat. + You can convert int to float with Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives7.res.expected b/tests/build_tests/super_errors/expected/primitives7.res.expected index 95aa2472c5..a6fe42b223 100644 --- a/tests/build_tests/super_errors/expected/primitives7.res.expected +++ b/tests/build_tests/super_errors/expected/primitives7.res.expected @@ -16,5 +16,5 @@ - Ensure all values in this calculation has the type float. You can convert between floats and ints via Belt.Float.toInt and Belt.Int.fromFloat. - Change the operator to +, which works on int - You can convert int to float with Belt.Int.toFloat. + You can convert int to float with Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/primitives9.res.expected b/tests/build_tests/super_errors/expected/primitives9.res.expected index b97f1b023d..c9068c29fb 100644 --- a/tests/build_tests/super_errors/expected/primitives9.res.expected +++ b/tests/build_tests/super_errors/expected/primitives9.res.expected @@ -8,4 +8,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/record_type_spreads_deep_sub.res.expected b/tests/build_tests/super_errors/expected/record_type_spreads_deep_sub.res.expected index cdbe9281a9..aa0178907f 100644 --- a/tests/build_tests/super_errors/expected/record_type_spreads_deep_sub.res.expected +++ b/tests/build_tests/super_errors/expected/record_type_spreads_deep_sub.res.expected @@ -11,4 +11,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/set_record_field_type_match.res.expected b/tests/build_tests/super_errors/expected/set_record_field_type_match.res.expected index d45880d7d2..fc634f630c 100644 --- a/tests/build_tests/super_errors/expected/set_record_field_type_match.res.expected +++ b/tests/build_tests/super_errors/expected/set_record_field_type_match.res.expected @@ -10,4 +10,4 @@ You're assigning something to this field that has type: int But this record field is of type: string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/stdlib_removed_in_error.res.expected b/tests/build_tests/super_errors/expected/stdlib_removed_in_error.res.expected index b9dbe7d8cd..5de1d8a86e 100644 --- a/tests/build_tests/super_errors/expected/stdlib_removed_in_error.res.expected +++ b/tests/build_tests/super_errors/expected/stdlib_removed_in_error.res.expected @@ -13,4 +13,4 @@ The incompatible parts: string vs int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/syntaxErrors4.res.expected b/tests/build_tests/super_errors/expected/syntaxErrors4.res.expected index 5cf63f8107..942d5cce09 100644 --- a/tests/build_tests/super_errors/expected/syntaxErrors4.res.expected +++ b/tests/build_tests/super_errors/expected/syntaxErrors4.res.expected @@ -15,4 +15,4 @@ This has type: string But it's expected to have type: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/type1.res.expected b/tests/build_tests/super_errors/expected/type1.res.expected index 6bc3692c57..4ca40ba83b 100644 --- a/tests/build_tests/super_errors/expected/type1.res.expected +++ b/tests/build_tests/super_errors/expected/type1.res.expected @@ -8,5 +8,5 @@ This has type: int But it's expected to have type: float - You can convert int to float with Belt.Int.toFloat. + You can convert int to float with Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/type2.res.expected b/tests/build_tests/super_errors/expected/type2.res.expected index 1b189ab2be..59a05b86eb 100644 --- a/tests/build_tests/super_errors/expected/type2.res.expected +++ b/tests/build_tests/super_errors/expected/type2.res.expected @@ -11,4 +11,4 @@ This has type: string But this function argument is expecting: int - You can convert string to int with Belt.Int.fromString. \ No newline at end of file + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/unicode_location.res.expected b/tests/build_tests/super_errors/expected/unicode_location.res.expected index e14d1c9d76..c7ac9eb8e5 100644 --- a/tests/build_tests/super_errors/expected/unicode_location.res.expected +++ b/tests/build_tests/super_errors/expected/unicode_location.res.expected @@ -10,4 +10,4 @@ This has type: int But string concatenation is expecting: string - You can convert int to string with Belt.Int.toString. \ No newline at end of file + You can convert int to string with Int.toString. \ No newline at end of file