Skip to content

Commit

Permalink
Typecheck Expressions - Use first argument for checking custom receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 20, 2024
1 parent 7a6145b commit 92b5ba6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/hir/from_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,11 @@ ::HIR::Function LowerHIR_Function(::HIR::ItemPath p, const ::AST::AttributeList&
rv.m_receiver = receiver;
if(receiver == HIR::Function::Receiver::Custom) {
rv.m_receiver_type = MonomorphiserNop().monomorph_type(f.args()[0].ty.span(), args.front().second, false);
ASSERT_BUG(f.args()[0].ty.span(), visit_ty_with(rv.m_receiver_type, [](const HIR::TypeRef& v){ return v.data().is_Generic() && v.data().as_Generic().is_self(); }), rv.m_receiver_type);
// Ensure that the reciever references `Self`
ASSERT_BUG(f.args()[0].ty.span(),
visit_ty_with(rv.m_receiver_type, [](const HIR::TypeRef& v){ return v.data().is_Generic() && v.data().as_Generic().is_self(); }),
rv.m_receiver_type
);
}
rv.m_abi = f.abi();
rv.m_unsafe = f.is_unsafe();
Expand Down
11 changes: 6 additions & 5 deletions src/hir_typeck/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4406,8 +4406,9 @@ const ::HIR::TypeRef* TraitResolution::check_method_receiver(const Span& sp, con
return &this->m_ivars.get_type(ty.data().as_Borrow().inner);
}
break;
case ::HIR::Function::Receiver::Custom:
ASSERT_BUG(sp, visit_ty_with(fcn.m_receiver_type, [](const HIR::TypeRef& v){ return v.data().is_Generic() && v.data().as_Generic().is_self(); }), fcn.m_receiver_type);
case ::HIR::Function::Receiver::Custom: {
const auto& receiver_type = fcn.m_args.front().second;
ASSERT_BUG(sp, visit_ty_with(receiver_type, [](const HIR::TypeRef& v){ return v.data().is_Generic() && v.data().as_Generic().is_self(); }), receiver_type);
// TODO: Handle custom-receiver functions
// - match_test_generics, if it succeeds return the matched Self
{
Expand All @@ -4426,12 +4427,12 @@ const ::HIR::TypeRef* TraitResolution::check_method_receiver(const Span& sp, con
TODO(Span(), "GetSelf::match_val " << g << " with " << sz);
}
} getself;
if( fcn.m_receiver_type.match_test_generics(sp, ty, this->m_ivars.callback_resolve_infer(), getself) ) {
ASSERT_BUG(sp, getself.detected_self_ty, "Unable to determine receiver type when matching " << fcn.m_receiver_type << " and " << ty);
if( receiver_type.match_test_generics(sp, ty, this->m_ivars.callback_resolve_infer(), getself) ) {
ASSERT_BUG(sp, getself.detected_self_ty, "Unable to determine receiver type when matching " << receiver_type << " and " << ty);
return &this->m_ivars.get_type(*getself.detected_self_ty);
}
}
return nullptr;
return nullptr; }
case ::HIR::Function::Receiver::Box:
if(const auto* ity = this->type_is_owned_box(sp, ty))
{
Expand Down

0 comments on commit 92b5ba6

Please sign in to comment.