From f74531bcbbd0de15996ff72d41132f89fd180509 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 3 Aug 2016 10:33:02 +0800 Subject: HIR Typecheck - Misc bugfixes --- src/hir_typeck/expr_cs.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- src/hir_typeck/helpers.cpp | 6 +++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 58a637e2..78c5bd5e 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1464,6 +1464,7 @@ namespace { (Infer, // Can't know anything //this->m_completed = true; + DEBUG("- Target type is still _"); ), (Diverge, BUG(sp, ""); @@ -1535,6 +1536,7 @@ namespace { ), (Pointer, // Allow with no link? + this->m_completed = true; ) ) ), @@ -1743,7 +1745,7 @@ namespace { void visit(::HIR::ExprNode_CallMethod& node) override { const auto& ty = this->context.get_type(node.m_value->m_res_type); //const auto ty = this->context.m_resolve.expand_associated_types(node.span(), this->context.get_type(node.m_value->m_res_type).clone()); - TRACE_FUNCTION_F("(CallMethod) {" << this->context.m_ivars.fmt_type(ty) << "}." << node.m_method); + TRACE_FUNCTION_F("(CallMethod) {" << this->context.m_ivars.fmt_type(ty) << "}." << node.m_method << node.m_params); // Make sure that no mentioned types are inferred until this method is known this->context.equate_types_shadow(node.span(), node.m_res_type); @@ -1757,7 +1759,6 @@ namespace { if( deref_count != ~0u ) { DEBUG("- deref_count = " << deref_count << ", fcn_path = " << fcn_path); - visit_call_populate_cache(this->context, node.span(), fcn_path, node.m_cache); node.m_method_path = mv$(fcn_path); // NOTE: Steals the params from the node @@ -1768,11 +1769,15 @@ namespace { ), (UfcsKnown, e.params = mv$(node.m_params); + //fix_param_count(sp, this->context, node.m_method_path, fcn.m_params, e.params); ), (UfcsInherent, e.params = mv$(node.m_params); + //fix_param_count(sp, this->context, node.m_method_path, fcn.m_params, e.params); ) ) + visit_call_populate_cache(this->context, node.span(), node.m_method_path, node.m_cache); + DEBUG("> m_method_path = " << node.m_method_path); assert( node.m_cache.m_arg_types.size() >= 1); @@ -2758,12 +2763,14 @@ namespace { return true; } context.possible_equate_type_to(r_e.index, ty_dst); + DEBUG("- Infer, add possibility"); return false; ) TU_IFLET(::HIR::TypeRef::Data, ty_dst.m_data, Infer, l_e, if( l_e.ty_class == ::HIR::InferClass::None ) { context.possible_equate_type_from(l_e.index, ty_src); + DEBUG("- Infer, add possibility"); return false; } // - Otherwise, it could be a deref? @@ -2877,6 +2884,28 @@ namespace { // - If `right`: ::core::marker::Unsize<`left`> // - If left can be dereferenced to right // - If left is a slice, right can unsize/deref (Defunct?) + TU_MATCH_DEF(::HIR::TypeRef::Data, (ty_dst.m_data), (e), + ( + ), + (TraitObject, + const auto& trait = e.m_trait.m_path; + // Check for trait impl + bool found = context.m_resolve.find_trait_impls(sp, trait.m_path, trait.m_params, ty_src, [&](auto impl, auto cmp) { + DEBUG("TraitObject coerce from - cmp="<span(), "Spare rules left after typecheck stabilised"); + } + // - Validate typeck { DEBUG("==== VALIDATE ==== (" << count << " rounds)"); diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 546221f6..6f3edf0c 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -888,16 +888,16 @@ bool HMTypeInferrence::types_equal(const ::HIR::TypeRef& rl, const ::HIR::TypeRe (UfcsKnown, if( lpe.item != rpe.item ) return false; - if( types_equal(*lpe.type, *rpe.type) ) + if( ! types_equal(*lpe.type, *rpe.type) ) return false; - if( pathparams_equal(lpe.trait.m_params, rpe.trait.m_params) ) + if( ! pathparams_equal(lpe.trait.m_params, rpe.trait.m_params) ) return false; return pathparams_equal(lpe.params, rpe.params); ), (UfcsInherent, if( lpe.item != rpe.item ) return false; - if( types_equal(*lpe.type, *rpe.type) ) + if( ! types_equal(*lpe.type, *rpe.type) ) return false; return pathparams_equal(lpe.params, rpe.params); ), -- cgit v1.2.3