return resolver.resolve_impl_block_self (impl_block);
}
+TyTy::BaseType *
+TypeCheckItem::ResolveImplBlockSelfWithInference (HIR::ImplBlock &impl,
+ Location locus)
+{
+ TypeCheckItem resolver;
+
+ bool failed_flag = false;
+ std::vector<TyTy::SubstitutionParamMapping> substitutions
+ = resolver.resolve_impl_block_substitutions (impl, failed_flag);
+ if (failed_flag)
+ {
+ return new TyTy::ErrorType (impl.get_mappings ().get_hirid ());
+ }
+
+ // now that we have the param mappings we need to query the self type
+ TyTy::BaseType *self = resolver.resolve_impl_block_self (impl);
+
+ // nothing to do
+ if (substitutions.empty () || self->is_concrete ())
+ return self;
+
+ // generate inference variables for the subst-param-mappings
+ std::vector<TyTy::SubstitutionArg> args;
+ for (auto &p : substitutions)
+ {
+ if (p.needs_substitution ())
+ {
+ TyTy::TyVar infer_var = TyTy::TyVar::get_implicit_infer_var (locus);
+ args.push_back (TyTy::SubstitutionArg (&p, infer_var.get_tyty ()));
+ }
+ else
+ {
+ TyTy::ParamType *param = p.get_param_ty ();
+ TyTy::BaseType *resolved = param->destructure ();
+ args.push_back (TyTy::SubstitutionArg (&p, resolved));
+ }
+ }
+
+ // create argument mappings
+ TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), {},
+ locus);
+
+ return SubstMapperInternal::Resolve (self, infer_arguments);
+}
+
void
TypeCheckItem::visit (HIR::TypeAlias &alias)
{
static TyTy::BaseType *ResolveImplBlockSelf (HIR::ImplBlock &impl_block);
+ static TyTy::BaseType *
+ ResolveImplBlockSelfWithInference (HIR::ImplBlock &impl, Location locus);
+
void visit (HIR::Module &module) override;
void visit (HIR::Function &function) override;
void visit (HIR::TypeAlias &alias) override;
= context->lookup_associated_trait_impl (impl_block_id,
&associated);
TyTy::BaseType *impl_block_ty
- = TypeCheckItem::ResolveImplBlockSelf (*associated_impl_block);
-
- if (impl_block_ty->needs_generic_substitutions ())
- impl_block_ty
- = SubstMapper::InferSubst (impl_block_ty, seg.get_locus ());
+ = TypeCheckItem::ResolveImplBlockSelfWithInference (
+ *associated_impl_block, seg.get_locus ());
prev_segment = unify_site (seg.get_mappings ().get_hirid (),
TyTy::TyWithLocation (prev_segment),