Skip to content

Commit

Permalink
add tests for float to int cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Il-Capitano committed Jan 8, 2024
1 parent 62ab741 commit 514d207
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/error/comptime/float_to_int_cast1.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float64' is outside the representable range of integer type 'uint8'
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float64' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: expression must be a constant expression
function test()
{
consteval _ = -1.0f64 as uint8;
}
8 changes: 8 additions & 0 deletions tests/error/comptime/float_to_int_cast2.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float32' is outside the representable range of integer type 'uint8'
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float32' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: expression must be a constant expression
function test()
{
consteval _ = -1.0f32 as uint8;
}
10 changes: 10 additions & 0 deletions tests/error/comptime/float_to_int_cast3.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float64' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: failed to evaluate expression at compile time
function test()
{
(consteval {
let x = -1.0f64;
let _ = x as uint8;
});
}
10 changes: 10 additions & 0 deletions tests/error/comptime/float_to_int_cast4.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// error: invalid cast in expression '-1.0 as uint8', floating-point value of type 'float32' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: failed to evaluate expression at compile time
function test()
{
(consteval {
let x = -1.0f32;
let _ = x as uint8;
});
}
10 changes: 10 additions & 0 deletions tests/error/comptime/float_to_int_cast5.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// error: invalid cast in expression '256.0 as uint8', floating-point value of type 'float64' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: failed to evaluate expression at compile time
function test()
{
(consteval {
let x = 256.0f64;
let _ = x as uint8;
});
}
10 changes: 10 additions & 0 deletions tests/error/comptime/float_to_int_cast6.bz
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// error: invalid cast in expression '256.0 as uint8', floating-point value of type 'float32' is outside the representable range of integer type 'uint8'
// note: while evaluating expression at compile time
// error: failed to evaluate expression at compile time
function test()
{
(consteval {
let x = 256.0f32;
let _ = x as uint8;
});
}

0 comments on commit 514d207

Please sign in to comment.