diff options
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 13 | ||||
-rw-r--r-- | src/hir_typeck/helpers.cpp | 35 | ||||
-rw-r--r-- | src/hir_typeck/helpers.hpp | 18 |
3 files changed, 45 insertions, 21 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index e81e0575..859dcf38 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -49,7 +49,12 @@ struct Context bool is_binop; friend ::std::ostream& operator<<(::std::ostream& os, const Associated& v) { - os << v.left_ty << " = " << "<" << v.impl_ty << " as " << v.trait << v.params << ">::" << v.name; + if( v.name == "" ) { + os << "req ty " << v.impl_ty << " impl " << v.trait << v.params; + } + else { + os << v.left_ty << " = " << "<" << v.impl_ty << " as " << v.trait << v.params << ">::" << v.name; + } return os; } }; @@ -314,6 +319,7 @@ namespace { const auto& trait_path = be.trait.m_path.m_path; context.equate_types_assoc(sp, ::HIR::TypeRef(), trait_path, mv$(trait_params.clone().m_types), real_type, ""); + // TODO: Either - Don't include the above impl bound, or change the below trait to the one that has that type for( const auto& assoc : be.trait.m_type_bounds ) { auto other_ty = monomorphise_type_with(sp, assoc.second, cache.m_monomorph_cb, true); context.equate_types_assoc(sp, other_ty, trait_path, mv$(trait_params.clone().m_types), real_type, assoc.first.c_str()); @@ -2841,14 +2847,15 @@ namespace { else if( count == 0 ) { // No applicable impl // - TODO: This should really only fire when there isn't an impl. But it currently fires when _ - DEBUG("No impl of " << v.trait << v.params << " for " << v.impl_ty); + DEBUG("No impl of " << v.trait << context.m_ivars.fmt(v.params) << " for " << context.m_ivars.fmt_type(v.impl_ty)); if( !context.m_ivars.type_contains_ivars(v.impl_ty) ) { ERROR(sp, E0000, "Failed to find an impl of " << v.trait << v.params << " for " << context.m_ivars.fmt_type(v.impl_ty)); } return false; } else if( count == 1 ) { - DEBUG("Only one impl " << v.trait << possible_params << " for " << possible_impl_ty << " - params=" << possible_params << ", ty=" << possible_impl_ty << ", out=" << output_type); + DEBUG("Only one impl " << v.trait << context.m_ivars.fmt(possible_params) << " for " << context.m_ivars.fmt_type(possible_impl_ty) + << " - params=" << possible_params << ", ty=" << possible_impl_ty << ", out=" << output_type); // Only one possible impl if( v.name != "" ) { context.equate_types(sp, v.left_ty, output_type); diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 13b26ab7..40fd0bfc 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -322,18 +322,6 @@ bool HMTypeInferrence::apply_defaults() void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) const { - struct H { - static void print_pp(const HMTypeInferrence& ctxt, ::std::ostream& os, const ::HIR::PathParams& pps) { - if( pps.m_types.size() > 0 ) { - os << "<"; - for(const auto& pp_t : pps.m_types) { - ctxt.print_type(os, pp_t); - os << ","; - } - os << ">"; - } - } - }; const auto& ty = this->get_type(tr); TU_MATCH(::HIR::TypeRef::Data, (ty.m_data), (e), (Infer, @@ -348,21 +336,21 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) TU_MATCH(::HIR::Path::Data, (e.path.m_data), (pe), (Generic, os << pe.m_path; - H::print_pp(*this, os, pe.m_params); + this->print_pathparams(os, pe.m_params); ), (UfcsKnown, os << "<"; this->print_type(os, *pe.type); os << " as " << pe.trait.m_path; - H::print_pp(*this, os, pe.trait.m_params); + this->print_pathparams(os, pe.trait.m_params); os << ">::" << pe.item; - H::print_pp(*this, os, pe.params); + this->print_pathparams(os, pe.params); ), (UfcsInherent, os << "<"; this->print_type(os, *pe.type); os << ">::" << pe.item; - H::print_pp(*this, os, pe.params); + this->print_pathparams(os, pe.params); ), (UfcsUnknown, BUG(Span(), "UfcsUnknown"); @@ -411,10 +399,10 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) ), (TraitObject, os << "(" << e.m_trait.m_path.m_path; - H::print_pp(*this, os, e.m_trait.m_path.m_params); + this->print_pathparams(os, e.m_trait.m_path.m_params); for(const auto& marker : e.m_markers) { os << "+" << marker.m_path; - H::print_pp(*this, os, marker.m_params); + this->print_pathparams(os, marker.m_params); } os << ")"; ), @@ -428,6 +416,17 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) ) ) } +void HMTypeInferrence::print_pathparams(::std::ostream& os, const ::HIR::PathParams& pps) const +{ + if( pps.m_types.size() > 0 ) { + os << "<"; + for(const auto& pp_t : pps.m_types) { + this->print_type(os, pp_t); + os << ","; + } + os << ">"; + } +} void HMTypeInferrence::expand_ivars(::HIR::TypeRef& type) { diff --git a/src/hir_typeck/helpers.hpp b/src/hir_typeck/helpers.hpp index 659f96b3..a0668c28 100644 --- a/src/hir_typeck/helpers.hpp +++ b/src/hir_typeck/helpers.hpp @@ -35,7 +35,20 @@ public: return os; } }; + struct FmtPP { + const HMTypeInferrence& ctxt; + const ::HIR::PathParams& pps; + FmtPP(const HMTypeInferrence& ctxt, const ::HIR::PathParams& pps): + ctxt(ctxt), + pps(pps) + {} + friend ::std::ostream& operator<<(::std::ostream& os, const FmtPP& x) { + x.ctxt.print_pathparams(os, x.pps); + return os; + } + }; +public: // ?? - Needed once, anymore? struct IVar { unsigned int alias; // If not ~0, this points to another ivar @@ -75,9 +88,14 @@ public: void dump() const; void print_type(::std::ostream& os, const ::HIR::TypeRef& tr) const; + void print_pathparams(::std::ostream& os, const ::HIR::PathParams& pps) const; + FmtType fmt_type(const ::HIR::TypeRef& tr) const { return FmtType(*this, tr); } + FmtPP fmt(const ::HIR::PathParams& v) const { + return FmtPP(*this, v); + } /// Add (and bind) all '_' types in `type` void add_ivars(::HIR::TypeRef& type); |