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
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
{"suite":"noir_bigcurve","name":"utils::derive_offset_generators::test_compute_and_print_offset_generators"}
21 changes: 19 additions & 2 deletions compiler/noirc_frontend/src/elaborator/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use noirc_errors::{Located, Location};
use rustc_hash::FxHashSet as HashSet;

use crate::{
DataType, Kind, QuotedType, Shared, Type, TypeVariable,
DataType, Kind, QuotedType, Shared, Type, TypeBindings, TypeVariable,
ast::{
ArrayLiteral, AsTraitPath, BinaryOpKind, BlockExpression, CallExpression, CastExpression,
ConstrainExpression, ConstrainKind, ConstructorExpression, Expression, ExpressionKind,
Expand Down Expand Up @@ -1474,6 +1474,9 @@ impl Elaborator<'_> {
let constraint = TraitConstraint { typ, trait_bound };

let the_trait = self.interner.get_trait(constraint.trait_bound.trait_id);
let self_type = the_trait.self_type_typevar.clone();
let kind = the_trait.self_type_typevar.kind();

let Some(definition) =
the_trait.find_method_or_constant(path.impl_item.as_str(), self.interner)
else {
Expand All @@ -1496,7 +1499,21 @@ impl Elaborator<'_> {
let id = self.interner.push_expr(HirExpression::Ident(ident.clone(), None));
self.interner.push_expr_location(id, location);

let typ = self.type_check_variable(ident, id, None);
let mut bindings = TypeBindings::default();

// In `<Type as Trait>::method` we know `Self` is `Type` so we bind that now
bindings.insert(self_type.id(), (self_type, kind, constraint.typ.clone()));

// TODO: set this to `true`. See https://github.com/noir-lang/noir/issues/8687
let push_required_type_variables = self.current_trait.is_none();

let typ = self.type_check_variable_with_bindings(
ident,
id,
None,
bindings,
push_required_type_variables,
);
self.interner.push_expr_type(id, typ.clone());
(id, typ)
}
Expand Down
21 changes: 21 additions & 0 deletions compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,3 +1783,24 @@ fn ambiguous_associated_type() {
"#;
check_errors!(src);
}

#[named]
#[test]
fn as_trait_path_self_type() {
let src = r#"
pub trait BigCurve<B> {
fn one() -> Self;
}

struct Bn254 {}

impl<B> BigCurve<B> for Bn254 {
fn one() -> Self { Bn254 {} }
}

fn main() {
let _ = <Bn254 as BigCurve<()>>::one();
}
"#;
assert_no_errors!(src);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

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

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

pub trait BigCurve<B> {
fn one() -> Self;
}

struct Bn254 {}

impl<B> BigCurve<B> for Bn254 {
fn one() -> Self { Bn254 {} }
}

fn main() {
let _ = <Bn254 as BigCurve<()>>::one();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14346112081613033525

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

Loading