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("{{}}") was printing "{{}}" instead of "{}" #6745

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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: 21 additions & 2 deletions compiler/noirc_printable_type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#[error("Failed calling external resolver. {0}")]
ExternalResolverError(#[from] jsonrpc::Error),

#[error("Assert message resolved after an unsatisified constrain. {0}")]

Check warning on line 84 in compiler/noirc_printable_type/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (unsatisified)
ResolvedAssertMessage(String),
}

Expand Down Expand Up @@ -233,12 +233,12 @@

(PrintableValue::Vec { array_elements, .. }, PrintableType::Tuple { types }) => {
output.push('(');
let mut elems = array_elements.iter().zip(types).peekable();

Check warning on line 236 in compiler/noirc_printable_type/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (elems)
while let Some((value, typ)) = elems.next() {

Check warning on line 237 in compiler/noirc_printable_type/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (elems)
output.push_str(
&PrintableValueDisplay::Plain(value.clone(), typ.clone()).to_string(),
);
if elems.peek().is_some() {

Check warning on line 241 in compiler/noirc_printable_type/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (elems)
output.push_str(", ");
}
}
Expand Down Expand Up @@ -278,6 +278,20 @@
let mut last_index = 0; // How far we've written from the template
let mut char_indices = template.char_indices().peekable();
while let Some((char_index, char)) = char_indices.next() {
// If we see a '}' it must be "}}" because the ones for interpolation are handled
// when we see '{'
if char == '}' {
// Write what we've seen so far in the template, including this '}'
write!(fmt, "{}", &template[last_index..=char_index])?;

// Skip the second '}'
let (_, closing_curly) = char_indices.next().unwrap();
assert_eq!(closing_curly, '}');

last_index = char_indices.peek().map(|(index, _)| *index).unwrap_or(template.len());
continue;
}

// Keep going forward until we find a '{'
if char != '{' {
continue;
Expand All @@ -290,7 +304,11 @@
// If it's '{{', write '{' and keep going
if char_indices.peek().map(|(_, char)| char) == Some(&'{') {
write!(fmt, "{{")?;
(last_index, _) = char_indices.next().unwrap();

// Skip the second '{'
char_indices.next().unwrap();

last_index = char_indices.peek().map(|(index, _)| *index).unwrap_or(template.len());
continue;
}

Expand Down Expand Up @@ -428,9 +446,10 @@
#[test]
fn printable_value_display_to_string_with_curly_escapes() {
let template = "hello {{world}} {{{{double_escape}}}}";
let expected = "hello {world} {{double_escape}}";
let display =
PrintableValueDisplay::<FieldElement>::FmtString(template.to_string(), vec![]);
assert_eq!(display.to_string(), template);
assert_eq!(display.to_string(), expected);
}

#[test]
Expand Down
Loading