Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(println): Enable printing of arrays/strings >2 in fmt strings #2947

Merged
merged 2 commits into from
Oct 2, 2023
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
23 changes: 17 additions & 6 deletions compiler/noirc_printable_type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,23 @@ fn convert_fmt_string_inputs(
{
let printable_type = fetch_printable_type(printable_value)?;
let type_size = printable_type.field_count() as usize;

let mut input_values_as_fields = input_and_printable_values[i..(i + type_size)]
.iter()
.flat_map(|param| vecmap(param.values(), |value| value.to_field()));

let value = decode_value(&mut input_values_as_fields, &printable_type);
let value = match printable_type {
PrintableType::Array { .. } | PrintableType::String { .. } => {
// Arrays and strings are represented in a single value vector rather than multiple separate input values
let mut input_values_as_fields = input_and_printable_values[i]
.values()
.into_iter()
.map(|value| value.to_field());
decode_value(&mut input_values_as_fields, &printable_type)
}
_ => {
// We must use a flat map here as each value in a struct will be in a separate input value
let mut input_values_as_fields = input_and_printable_values[i..(i + type_size)]
.iter()
.flat_map(|param| vecmap(param.values(), |value| value.to_field()));
decode_value(&mut input_values_as_fields, &printable_type)
}
};

output.push((value, printable_type));
}
Expand Down
18 changes: 18 additions & 0 deletions tooling/nargo_cli/tests/execution_success/debug_logs/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ fn main(x : Field, y : pub Field) {

let struct_string = if x != 5 { f"{foo}" } else { f"{bar}" };
std::println(struct_string);

regression_2906();
}

fn string_identity(string: fmtstr<14, (Field, Field)>) -> fmtstr<14, (Field, Field)> {
Expand All @@ -62,3 +64,19 @@ struct fooStruct {
my_struct: myStruct,
foo: Field,
}

fn regression_2906() {
let array_two_vals = [1, 2];
dep::std::println(f"array_two_vals: {array_two_vals}");

let label_two_vals = "12";
dep::std::println(f"label_two_vals: {label_two_vals}");

let array_five_vals = [1, 2, 3, 4, 5];
dep::std::println(f"array_five_vals: {array_five_vals}");

let label_five_vals = "12345";
dep::std::println(f"label_five_vals: {label_five_vals}");

dep::std::println(f"array_five_vals: {array_five_vals}, label_five_vals: {label_five_vals}");
}