Skip to content

Commit

Permalink
added tests for negative cases, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
massivefermion authored and lpil committed Jan 9, 2025
1 parent 0b8a0cb commit c9ca4b7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ The error from the encryption library was:
title: "Float is outside Erlang's floating point range".into(),
text: wrap("This float value is too large to be represented by \
Erlang's floating point type. To avoid this error float values must be in the range \
-1.7976931348623157e308f64 - 1.7976931348623157e308f64."),
-1.7976931348623157e308 - 1.7976931348623157e308."),
hint: None,
level: Level::Error,
location: Some(Location {
Expand Down
15 changes: 15 additions & 0 deletions compiler-core/src/type_/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,3 +2670,18 @@ fn out_of_range_erlang_float_in_pattern() {
fn out_of_range_erlang_float_in_const() {
assert_module_error!(r#"const x = 1.8e308"#);
}

#[test]
fn negative_out_of_range_erlang_float() {
assert_error!(r#"-1.8e308"#);
}

#[test]
fn negative_out_of_range_erlang_float_in_pattern() {
assert_error!(r#"let assert [-1.8e308, b] = [x, y]"#);
}

#[test]
fn negative_out_of_range_erlang_float_in_const() {
assert_module_error!(r#"const x = -1.8e308"#);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: compiler-core/src/type_/tests/errors.rs
expression: "-1.8e308"
snapshot_kind: text
---
----- SOURCE CODE
-1.8e308

----- ERROR
error: Float is outside Erlang's floating point range
┌─ /src/one/two.gleam:1:1
1-1.8e308
^^^^^^^^

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: compiler-core/src/type_/tests/errors.rs
expression: const x = -1.8e308
snapshot_kind: text
---
----- SOURCE CODE
const x = -1.8e308

----- ERROR
error: Float is outside Erlang's floating point range
┌─ /src/one/two.gleam:1:11
1const x = -1.8e308
^^^^^^^^

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: compiler-core/src/type_/tests/errors.rs
expression: "let assert [-1.8e308, b] = [x, y]"
snapshot_kind: text
---
----- SOURCE CODE
let assert [-1.8e308, b] = [x, y]

----- ERROR
error: Unknown variable
┌─ /src/one/two.gleam:1:29
1let assert [-1.8e308, b] = [x, y]
^

The name `x` is not in scope here.

error: Float is outside Erlang's floating point range
┌─ /src/one/two.gleam:1:13
1let assert [-1.8e308, b] = [x, y]
^^^^^^^^

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ error: Float is outside Erlang's floating point range

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ error: Float is outside Erlang's floating point range

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ error: Float is outside Erlang's floating point range

This float value is too large to be represented by Erlang's floating point
type. To avoid this error float values must be in the range
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
-1.7976931348623157e308 - 1.7976931348623157e308.

0 comments on commit c9ca4b7

Please sign in to comment.