diff --git a/compiler/noirc_frontend/src/hir/comptime/value.rs b/compiler/noirc_frontend/src/hir/comptime/value.rs index 6ee7993c71c..417a7cbdf30 100644 --- a/compiler/noirc_frontend/src/hir/comptime/value.rs +++ b/compiler/noirc_frontend/src/hir/comptime/value.rs @@ -578,7 +578,10 @@ impl Value { if value < 0 { vec![ Token::Minus, - Token::Int((-value as u128).into(), Some(IntegerTypeSuffix::I8)), + Token::Int( + u128::from(value.unsigned_abs()).into(), + Some(IntegerTypeSuffix::I8), + ), ] } else { vec![Token::Int((value as u128).into(), Some(IntegerTypeSuffix::I8))] @@ -588,7 +591,10 @@ impl Value { if value < 0 { vec![ Token::Minus, - Token::Int((-value as u128).into(), Some(IntegerTypeSuffix::I16)), + Token::Int( + u128::from(value.unsigned_abs()).into(), + Some(IntegerTypeSuffix::I16), + ), ] } else { vec![Token::Int((value as u128).into(), Some(IntegerTypeSuffix::I16))] @@ -598,7 +604,10 @@ impl Value { if value < 0 { vec![ Token::Minus, - Token::Int((-value as u128).into(), Some(IntegerTypeSuffix::I32)), + Token::Int( + u128::from(value.unsigned_abs()).into(), + Some(IntegerTypeSuffix::I32), + ), ] } else { vec![Token::Int((value as u128).into(), Some(IntegerTypeSuffix::I32))] @@ -608,7 +617,10 @@ impl Value { if value < 0 { vec![ Token::Minus, - Token::Int((-value as u128).into(), Some(IntegerTypeSuffix::I64)), + Token::Int( + u128::from(value.unsigned_abs()).into(), + Some(IntegerTypeSuffix::I64), + ), ] } else { vec![Token::Int((value as u128).into(), Some(IntegerTypeSuffix::I64))] diff --git a/compiler/noirc_frontend/src/tests/meta_quote_roundtrip.rs b/compiler/noirc_frontend/src/tests/meta_quote_roundtrip.rs index e1c30f1e75d..b107efe8f9f 100644 --- a/compiler/noirc_frontend/src/tests/meta_quote_roundtrip.rs +++ b/compiler/noirc_frontend/src/tests/meta_quote_roundtrip.rs @@ -73,27 +73,29 @@ proptest! { assert_no_errors(&src); } - // TODO(https://github.com/noir-lang/noir/issues/10328): Although it is a very low chance, all these tests have the possibility to be flakey - // #[test] - // fn roundtrip_i8_values(n in any::()) { - // let src = make_roundtrip_test("i8", n.to_string()); - // assert_no_errors(&src); - // } - // #[test] - // fn roundtrip_i16_values(n in any::()) { - // let src = make_roundtrip_test("i16", n.to_string()); - // assert_no_errors(&src); - // } - // #[test] - // fn roundtrip_i32_values(n in any::()) { - // let src = make_roundtrip_test("i32", n.to_string()); - // assert_no_errors(&src); - // } - // #[test] - // fn roundtrip_i64_values(n in any::()) { - // let src = make_roundtrip_test("i64", n.to_string()); - // assert_no_errors(&src); - // } + #[test] + fn roundtrip_i8_values(n in any::()) { + let src = make_roundtrip_test("i8", n.to_string()); + assert_no_errors(&src); + } + + #[test] + fn roundtrip_i16_values(n in any::()) { + let src = make_roundtrip_test("i16", n.to_string()); + assert_no_errors(&src); + } + + #[test] + fn roundtrip_i32_values(n in any::()) { + let src = make_roundtrip_test("i32", n.to_string()); + assert_no_errors(&src); + } + + #[test] + fn roundtrip_i64_values(n in any::()) { + let src = make_roundtrip_test("i64", n.to_string()); + assert_no_errors(&src); + } } #[test] @@ -102,9 +104,7 @@ fn roundtrip_zero_field() { assert_no_errors(&src); } -// TODO(https://github.com/noir-lang/noir/issues/10328) #[test] -#[ignore] fn roundtrip_i64_min() { let src = make_roundtrip_test("i64", i64::MIN.to_string()); assert_no_errors(&src);