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
34 changes: 28 additions & 6 deletions compiler/noirc_frontend/src/tests/unused_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,15 @@ fn considers_struct_as_constructed_if_trait_method_is_called() {
#[test]
fn considers_struct_as_constructed_if_mentioned_in_let_type() {
let src = "
pub struct Bar {}
struct Bar {}

pub fn foo(array: [Bar; 1]) {
fn foo(array: [Bar; 1]) {
let _: Bar = array[0];
}

fn main() {}
fn main() {
let _ = foo;
}
";
assert_no_errors!(src);
}
Expand All @@ -347,13 +349,15 @@ fn considers_struct_as_constructed_if_mentioned_in_let_type() {
#[test]
fn considers_struct_as_constructed_if_mentioned_in_return_type() {
let src = "
pub struct Bar {}
struct Bar {}

pub fn foo(array: [Bar; 1]) -> Bar {
fn foo(array: [Bar; 1]) -> Bar {
array[0]
}

fn main() {}
fn main() {
let _ = foo;
}
";
assert_no_errors!(src);
}
Expand Down Expand Up @@ -387,3 +391,21 @@ fn considers_struct_as_constructed_if_passed_in_generic_args_in_function_call()
";
assert_no_errors!(src);
}

#[named]
#[test]
fn does_not_consider_struct_as_constructed_if_mentioned_in_function_argument() {
let src = "
struct Bar {}
^^^ struct `Bar` is never constructed
~~~ struct is never constructed

fn foo(_: [Bar; 1]) {}

fn main() {
foo();
^^^^^ Function expects 1 parameter but 0 were given
}
";
check_errors!(src);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[package]
name = "noirc_frontend_tests_unused_items_does_not_consider_struct_as_constructed_if_mentioned_in_function_argument"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

struct Bar {}

fn foo(_: [Bar; 1]) {}

fn main() {
foo();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6625675327575863409
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning: struct `Bar` is never constructed
┌─ src/main.nr:2:12
2 │ struct Bar {}
│ --- struct is never constructed

error: Function expects 1 parameter but 0 were given
┌─ src/main.nr:7:9
7 │ foo();
│ -----

Aborting due to 1 previous error
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

pub struct Bar {}
struct Bar {}

pub fn foo(array: [Bar; 1]) {
fn foo(array: [Bar; 1]) {
let _: Bar = array[0];
}

fn main() {}
fn main() {
let _ = foo;
}

Original file line number Diff line number Diff line change
@@ -1 +1 @@
38851938633219158
12368942904043175809
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

pub struct Bar {}
struct Bar {}

pub fn foo(array: [Bar; 1]) -> Bar {
fn foo(array: [Bar; 1]) -> Bar {
array[0]
}

fn main() {}
fn main() {
let _ = foo;
}

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2517654725056587726
1898526012180092460
Loading