diff --git a/CHANGELOG.md b/CHANGELOG.md index 648355ab873..1fda5d6efe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -200,6 +200,10 @@ nested inside another pattern would produce invalid code on Javascript. ([yoshi](https://github.com/joshi-monster)) +- Fixed a bug where expressions which use an unsafe integer on JavaScript would + not emit a warning if an @external function had been referenced. + ([Richard Viney](https://github.com/richard-viney)) + ## v1.6.1 - 2024-11-19 ### Bug fixed diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index 6e24b2dc827..fd97d955825 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -317,7 +317,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { .. } => { if self.environment.target == Target::JavaScript - && !self.implementations.uses_javascript_externals + && !self.current_function_definition.has_javascript_external { check_javascript_int_safety(&int_value, location, self.problems); } diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__javascript_unsafe_int_with_external_function_call.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__javascript_unsafe_int_with_external_function_call.snap index 865bdf3b98b..3ed3d4a3243 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__javascript_unsafe_int_with_external_function_call.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__javascript_unsafe_int_with_external_function_call.snap @@ -1,11 +1,11 @@ --- source: compiler-core/src/type_/tests/warnings.rs -expression: "\npub fn main() {\n 9_007_199_254_740_992 + helper()\n}\n\n@external(javascript, \"a\", \"b\")\nfn helper() -> Int\n" +expression: "\npub fn main() {\n helper() + 9_007_199_254_740_992\n}\n\n@external(javascript, \"a\", \"b\")\nfn helper() -> Int\n" --- ----- SOURCE CODE pub fn main() { - 9_007_199_254_740_992 + helper() + helper() + 9_007_199_254_740_992 } @external(javascript, "a", "b") @@ -14,10 +14,10 @@ fn helper() -> Int ----- WARNING warning: Int is outside JavaScript's safe integer range - ┌─ /src/warning/wrn.gleam:3:3 + ┌─ /src/warning/wrn.gleam:3:14 │ -3 │ 9_007_199_254_740_992 + helper() - │ ^^^^^^^^^^^^^^^^^^^^^ This is not a safe integer value on JavaScript +3 │ helper() + 9_007_199_254_740_992 + │ ^^^^^^^^^^^^^^^^^^^^^ This is not a safe integer value on JavaScript This integer value is too large to be represented accurately by JavaScript's number type. To avoid this warning integer values must be in diff --git a/compiler-core/src/type_/tests/warnings.rs b/compiler-core/src/type_/tests/warnings.rs index 94140477f7a..1367ad20651 100644 --- a/compiler-core/src/type_/tests/warnings.rs +++ b/compiler-core/src/type_/tests/warnings.rs @@ -2712,7 +2712,7 @@ fn javascript_unsafe_int_with_external_function_call() { assert_js_warning!( r#" pub fn main() { - 9_007_199_254_740_992 + helper() + helper() + 9_007_199_254_740_992 } @external(javascript, "a", "b")