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: don't always select trait impl when verifying trait constraints #7041

Merged
merged 11 commits into from
Jan 14, 2025
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'context> Elaborator<'context> {
let func_id = unresolved_trait.method_ids[&name.0.contents];
let mut where_clause = where_clause.to_vec();

// Attach any trait constraints on the trait to the function
// Attach any trait constraints on the trait to the function,
where_clause.extend(unresolved_trait.trait_def.where_clause.clone());

this.resolve_trait_function(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_7038"
type = "bin"
authors = [""]
compiler_version = ">=0.30.0"

[dependencies]
40 changes: 40 additions & 0 deletions test_programs/compile_success_empty/regression_7038/src/main.nr
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
trait BigNumTrait {}

pub struct MyBigNum;

impl crate::BigNumTrait for MyBigNum {}

trait CurveParamsTrait<BigNum>
where
BigNum: BigNumTrait,
{
fn one();
}

pub struct BN254Params;
impl CurveParamsTrait<MyBigNum> for BN254Params {

fn one() {}
}

trait BigCurveTrait {
fn two();
}

pub struct BigCurve<BigNum, CurveParams> {}

type BN254 = BigCurve<MyBigNum, BN254Params>;

impl<BigNum, CurveParams> BigCurveTrait for BigCurve<BigNum, CurveParams>
where
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
fn two() {
let _ = CurveParams::one();
}
}

fn main() {
let _ = BN254::two();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_7038_2"
type = "bin"
authors = [""]
compiler_version = ">=0.30.0"

[dependencies]
37 changes: 37 additions & 0 deletions test_programs/compile_success_empty/regression_7038_2/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
trait BigNumTrait {}

pub struct MyBigNum;

impl crate::BigNumTrait for MyBigNum {}

trait CurveParamsTrait<BigNum>
where
BigNum: BigNumTrait,
{
fn one() {}
}

pub struct BN254Params;
impl CurveParamsTrait<MyBigNum> for BN254Params {}

trait BigCurveTrait {
fn two();
}

pub struct BigCurve<BigNum, CurveParams> {}

type BN254 = BigCurve<MyBigNum, BN254Params>;

impl<BigNum, CurveParams> BigCurveTrait for BigCurve<BigNum, CurveParams>
where
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
fn two() {
let _ = CurveParams::one();
}
}

fn main() {
let _ = BN254::two();
}
Loading