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
46 changes: 45 additions & 1 deletion compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::elaborator::FrontendOptions;

use crate::assert_no_errors;
use crate::tests::Expect;
use crate::{assert_no_errors, check_monomorphization_error};
use crate::{check_errors, get_program_with_options};

#[named]
Expand Down Expand Up @@ -1628,3 +1628,47 @@ fn accesses_associated_type_inside_trait_using_self() {
"#;
assert_no_errors!(src);
}

#[named]
#[test]
fn serialize_test_with_a_previous_unrelated_definition() {
let src = r#"
// If you remove this Trait definition, the code compiles fine. That's the bug.
pub trait Trait {}

trait Serialize {
let Size: u32;

fn serialize(self);
}

impl<A, B> Serialize for (A, B)
where
A: Serialize,
B: Serialize,
{
let Size: u32 = <A as Serialize>::Size + <B as Serialize>::Size;

fn serialize(self: Self) {
self.0.serialize();
^^^^^^^^^^^^^^^^ No matching impl found for `(Field, Field): Serialize<Size = (3 - _)>`
~~~~~~~~~~~~~~~~ No impl for `(Field, Field): Serialize<Size = (3 - _)>`
}
}

impl Serialize for Field {
let Size: u32 = 1;

fn serialize(self) { }
}

fn main() {
let x = (((1, 2), 5), 9);
x.serialize();
}
"#;

// In reality there should be no error here, so any error squiggles should be removed.
// See https://github.com/noir-lang/noir/issues/8780
check_monomorphization_error!(&src);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

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

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

// If you remove this Trait definition, the code compiles fine. That's the bug.
pub trait Trait {}

trait Serialize {
let Size: u32;

fn serialize(self);
}

impl<A, B> Serialize for (A, B)
where
A: Serialize,
B: Serialize,
{
let Size: u32 = <A as Serialize>::Size + <B as Serialize>::Size;

fn serialize(self: Self) {
self.0.serialize();
}
}

impl Serialize for Field {
let Size: u32 = 1;

fn serialize(self) { }
}

fn main() {
let x = (((1, 2), 5), 9);
x.serialize();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6336765763415174448
3 changes: 2 additions & 1 deletion tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
// There's no "src/main.nr" here so it's trickier to make this work
"overlapping_dep_and_mod",
// bug
"poseidonsponge_x5_254",

Check warning on line 131 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (poseidonsponge)
// bug
"regression_5045",
// bug
Expand Down Expand Up @@ -192,7 +192,7 @@

/// These tests are ignored because of existing bugs in `nargo expand`.
/// As the bugs are fixed these tests should be removed from this list.
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 16] = [
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 17] = [
"noirc_frontend_tests_arithmetic_generics_checked_casts_do_not_prevent_canonicalization",
"noirc_frontend_tests_check_trait_as_type_as_fn_parameter",
"noirc_frontend_tests_check_trait_as_type_as_two_fn_parameters",
Expand All @@ -201,6 +201,7 @@
"noirc_frontend_tests_traits_calls_trait_function_if_it_is_in_scope",
"noirc_frontend_tests_traits_calls_trait_function_if_it_is_only_candidate_in_scope",
"noirc_frontend_tests_traits_calls_trait_function_if_it_is_only_candidate_in_scope_in_nested_module_using_super",
"noirc_frontend_tests_traits_serialize_test_with_a_previous_unrelated_definition",
"noirc_frontend_tests_traits_trait_alias_polymorphic_inheritance",
"noirc_frontend_tests_traits_trait_alias_single_member",
"noirc_frontend_tests_traits_trait_alias_two_members",
Expand Down Expand Up @@ -689,7 +690,7 @@
writeln!(test_file, "}}").unwrap();
}

/// Here we check, for every program in `test_programs/exeuction_success`, that:

Check warning on line 693 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (exeuction)
/// 1. `nargo expand` works on it
/// 2. That the output of the original program is the same as the output of the expanded program
/// (that is, we run `nargo execute` on the original program and the expanded program and compare the output)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading