Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ impl Value {
location: Location,
) -> IResult<Vec<Token>> {
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)) => {
Expand All @@ -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])
Expand Down
28 changes: 28 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<let N: u32> {
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);
}