diff --git a/compiler/noirc_frontend/src/hir/comptime/value.rs b/compiler/noirc_frontend/src/hir/comptime/value.rs index c5818c20c57..fdac95a07fe 100644 --- a/compiler/noirc_frontend/src/hir/comptime/value.rs +++ b/compiler/noirc_frontend/src/hir/comptime/value.rs @@ -429,6 +429,9 @@ impl Value { location: Location, ) -> IResult> { let token = match self { + Value::Unit => { + return Ok(vec![Token::LeftParen, Token::RightParen]); + } Value::Quoted(tokens) => return Ok(unwrap_rc(tokens)), Value::Type(typ) => Token::QuotedType(interner.push_quoted_type(typ)), Value::Expr(ExprValue::Expression(expr)) => { @@ -443,6 +446,40 @@ impl Value { Value::UnresolvedType(typ) => { Token::InternedUnresolvedTypeData(interner.push_unresolved_type_data(typ)) } + Value::U1(bool) => Token::Bool(bool), + Value::U8(value) => Token::Int((value as u128).into()), + Value::U16(value) => Token::Int((value as u128).into()), + Value::U32(value) => Token::Int((value as u128).into()), + Value::U64(value) => Token::Int((value as u128).into()), + Value::I8(value) => { + if value < 0 { + return Ok(vec![Token::Minus, Token::Int((-value as u128).into())]); + } else { + Token::Int((value as u128).into()) + } + } + Value::I16(value) => { + if value < 0 { + return Ok(vec![Token::Minus, Token::Int((-value as u128).into())]); + } else { + Token::Int((value as u128).into()) + } + } + Value::I32(value) => { + if value < 0 { + return Ok(vec![Token::Minus, Token::Int((-value as u128).into())]); + } else { + Token::Int((value as u128).into()) + } + } + Value::I64(value) => { + if value < 0 { + return Ok(vec![Token::Minus, Token::Int((-value as u128).into())]); + } else { + Token::Int((value as u128).into()) + } + } + Value::Field(value) => Token::Int(value), other => Token::UnquoteMarker(other.into_hir_expression(interner, location)?), }; Ok(vec![token]) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index a30907211a3..e7dbe11f0d1 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -3341,3 +3341,31 @@ fn warns_on_re_export_of_item_with_less_visibility() { ) )); } + +#[test] +fn unoquted_integer_as_integer_token() { + let src = r#" + trait Serialize { + fn serialize() {} + } + + #[attr] + fn foobar() {} + + fn attr(_f: FunctionDefinition) -> Quoted { + let serialized_len = 1; + // We are testing that when we unoqute $serialized_len, it's unquoted + // as the token `1` and not as something else that later won't be parsed correctly + // in the context of a generic argument. + quote { + impl Serialize<$serialized_len> for Field { + fn serialize() { } + } + } + } + + fn main() {} + "#; + + assert_no_errors(src); +}