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: operator overloading & static trait method references resolving to generic impls #3967

Merged
merged 11 commits into from
Jan 8, 2024
10 changes: 5 additions & 5 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
.collect()
}

// TODO(vitkov): Move this out of here and into type_check

Check warning on line 458 in compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (vitkov)
pub(crate) fn check_methods_signatures(
resolver: &mut Resolver,
impl_methods: &Vec<(FileId, FuncId)>,
Expand All @@ -474,18 +474,18 @@
let trait_methods = std::mem::take(&mut the_trait.methods);

for (file_id, func_id) in impl_methods {
let impl_method = resolver.interner.function_meta(func_id);
let func_name = resolver.interner.function_name(func_id).to_owned();

let mut typecheck_errors = Vec::new();

// This is None in the case where the impl block has a method that's not part of the trait.
// If that's the case, a `MethodNotInTrait` error has already been thrown, and we can ignore
// the impl method, since there's nothing in the trait to match its signature against.
if let Some(trait_method) =
trait_methods.iter().find(|method| method.name.0.contents == func_name)
{
let impl_function_type = impl_method.typ.instantiate(resolver.interner);
let mut typecheck_errors = Vec::new();
let impl_method = resolver.interner.function_meta(func_id);

let (impl_function_type, _) = impl_method.typ.instantiate(resolver.interner);

let impl_method_generic_count =
impl_method.typ.generic_count() - trait_impl_generic_count;
Expand All @@ -505,7 +505,7 @@
errors.push((error.into(), *file_id));
}

if let Type::Function(impl_params, _, _) = impl_function_type.0 {
if let Type::Function(impl_params, _, _) = impl_function_type {
if trait_method.arguments().len() == impl_params.len() {
// Check the parameters of the impl method against the parameters of the trait method
let args = trait_method.arguments().iter();
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/hir_def/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct Trait {
pub self_type_typevar_id: TypeVariableId,
pub self_type_typevar: TypeVariable,
}

#[derive(Debug)]
pub struct TraitImpl {
pub ident: Ident,
Expand Down
Loading
Loading