Skip to content

Commit

Permalink
fix: Fix comptime type formatting (#6079)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #6077

## Summary\*

The change made to `impl Debug for Type` to display kinds differently
was breaking the use case of formatting types into a format string then
using `.quoted_contents()` to quote the contents of the string.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
jfecher authored Sep 18, 2024
1 parent 426f295 commit e678091
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ impl<'value, 'interner> Display for ValuePrinter<'value, 'interner> {
}
}
Value::Zeroed(typ) => write!(f, "(zeroed {typ})"),
Value::Type(typ) => write!(f, "{:?}", typ),
Value::Type(typ) => write!(f, "{}", typ),
Value::Expr(ExprValue::Expression(expr)) => {
write!(f, "{}", remove_interned_in_expression_kind(self.interner, expr.clone()))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_6077"
type = "bin"
authors = [""]
compiler_version = ">=0.30.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = 0
28 changes: 28 additions & 0 deletions test_programs/compile_success_empty/regression_6077/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
struct WeirdStruct<T, U> {
a: T,
b: U,
}

#[mangle_fn]
pub fn my_fn() -> [u8; 3] {
[0; 3]
}

comptime fn mangle_fn(f: FunctionDefinition) {
let return_type = f.return_type();

// This relies on how types are displayed
let generics = f"Field,{return_type}".quoted_contents();
let new_return_type = quote { WeirdStruct<$generics>}.as_type();

let new_body = quote {
{
WeirdStruct { a: 1, b: [0;3] }
}
}.as_expr().unwrap();

f.set_return_type(new_return_type);
f.set_body(new_body);
}

fn main() {}

0 comments on commit e678091

Please sign in to comment.