-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tf/restructure-integration-tests
- Loading branch information
Showing
21 changed files
with
280 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
tooling/nargo_cli/tests/execution_success/conditional_regression_underflow/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "conditional_underflow" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
tooling/nargo_cli/tests/execution_success/conditional_regression_underflow/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = "4" |
15 changes: 15 additions & 0 deletions
15
tooling/nargo_cli/tests/execution_success/conditional_regression_underflow/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Regression test for https://github.com/noir-lang/noir/issues/3493 | ||
fn main(x: u4) { | ||
if x == 10 { | ||
x + 15; | ||
} | ||
if x == 9 { | ||
x << 3; | ||
} | ||
if x == 8 { | ||
x * 3; | ||
} | ||
if x == 7 { | ||
x - 8; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod array; | ||
mod infix; | ||
|
||
pub(crate) use array::rewrite as array; | ||
pub(crate) use infix::rewrite as infix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use noirc_frontend::{hir::resolution::errors::Span, token::Token, Expression}; | ||
|
||
use crate::{ | ||
utils::{Expr, FindToken}, | ||
visitor::FmtVisitor, | ||
}; | ||
|
||
pub(crate) fn rewrite(mut visitor: FmtVisitor, array: Vec<Expression>, array_span: Span) -> String { | ||
let pattern: &[_] = &[' ', '\t']; | ||
|
||
visitor.indent.block_indent(visitor.config); | ||
let nested_indent = visitor.shape(); | ||
|
||
let indent_str = nested_indent.indent.to_string(); | ||
|
||
let mut last_position = array_span.start() + 1; | ||
let end_position = array_span.end() - 1; | ||
|
||
let mut items = array.into_iter().peekable(); | ||
|
||
let mut result = Vec::new(); | ||
while let Some(item) = items.next() { | ||
let item_span = item.span; | ||
|
||
let start: u32 = last_position; | ||
let end = item_span.start(); | ||
|
||
let leading = visitor.slice(start..end).trim_matches(pattern); | ||
let item = visitor.format_sub_expr(item); | ||
let next_start = items.peek().map_or(end_position, |expr| expr.span.start()); | ||
let trailing = visitor.slice(item_span.end()..next_start); | ||
let offset = trailing | ||
.find_token(Token::Comma) | ||
.map(|span| span.end() as usize) | ||
.unwrap_or(trailing.len()); | ||
let trailing = trailing[..offset].trim_end_matches(',').trim_matches(pattern); | ||
last_position = item_span.end() + offset as u32; | ||
|
||
let (leading, _) = visitor.format_comment_in_block(leading, 0, false); | ||
let (trailing, _) = visitor.format_comment_in_block(trailing, 0, false); | ||
|
||
result.push(Expr { leading, value: item, trailing, different_line: false }); | ||
} | ||
|
||
let slice = visitor.slice(last_position..end_position); | ||
let (comment, _) = visitor.format_comment_in_block(slice, 0, false); | ||
result.push(Expr { | ||
leading: "".into(), | ||
value: "".into(), | ||
trailing: comment, | ||
different_line: false, | ||
}); | ||
|
||
visitor.indent.block_unindent(visitor.config); | ||
|
||
let mut items_str = String::new(); | ||
let mut items = result.into_iter().peekable(); | ||
while let Some(next) = items.next() { | ||
items_str.push_str(&next.leading); | ||
if next.leading.contains('\n') && !next.value.is_empty() { | ||
items_str.push_str(&indent_str); | ||
} | ||
items_str.push_str(&next.value); | ||
items_str.push_str(&next.trailing); | ||
|
||
if let Some(item) = items.peek() { | ||
if !item.value.is_empty() { | ||
items_str.push(','); | ||
} | ||
|
||
if !item.leading.contains('\n') && !next.value.is_empty() { | ||
items_str.push(' '); | ||
} | ||
} | ||
} | ||
|
||
crate::visitor::expr::wrap_exprs( | ||
"[", | ||
"]", | ||
items_str.trim().into(), | ||
nested_indent, | ||
visitor.shape(), | ||
true, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.