From b61f4dc10daca6590b526801d971d4a8368062e9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 8 Jun 2016 23:29:51 +0800 Subject: HIR Typecheck - Runs fully over libcore, no validation yet --- src/hir/hir.cpp | 8 ++++++-- src/hir/type.cpp | 4 ++++ src/hir_typeck/expr.cpp | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index dc0aca0a..1dce63f8 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -32,9 +32,10 @@ namespace HIR { namespace { bool matches_type_int(const ::HIR::GenericParams& params, const ::HIR::TypeRef& left, const ::HIR::TypeRef& right_in, ::HIR::t_cb_resolve_type ty_res) { - //DEBUG("left = " << left << ", right = " << right); assert(! left.m_data.is_Infer() ); - const auto& right = (right_in.m_data.is_Infer() ? ty_res(right_in) : right_in); + const auto& right = (right_in.m_data.is_Infer() || right_in.m_data.is_Generic() ? ty_res(right_in) : right_in); + + //DEBUG("left = " << left << ", right = " << right); // TODO: What indicates what out of ty_res? @@ -42,6 +43,9 @@ namespace { // TODO: Why is this false? A _ type could match anything return false; } + if( right.m_data.is_Generic() ) { + return left.m_data.is_Generic(); + } if( left.m_data.is_Generic() ) { // True? (TODO: Check bounds?) diff --git a/src/hir/type.cpp b/src/hir/type.cpp index f3ba220f..d324bc57 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -416,6 +416,7 @@ namespace { } ::HIR::TypeRef::Compare HIR::TypeRef::compare_with_paceholders(const Span& sp, const ::HIR::TypeRef& x, ::std::function resolve_placeholder) const { + TRACE_FUNCTION_F(*this << " ?= " << x); assert( !this->m_data.is_Infer() ); const auto& right = (x.m_data.is_Infer() ? resolve_placeholder(x) : (x.m_data.is_Generic() ? resolve_placeholder(x) : x)); @@ -460,6 +461,9 @@ namespace { throw ""; ) + // If righthand is a type parameter, it can only match another type parameter + // - See `(Generic,` below + if( this->m_data.tag() != right.m_data.tag() ) { return Compare::Unequal; } diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 987b3789..043456e0 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -1001,18 +1001,24 @@ namespace { equality_typeparams(lpe.m_params, rpe.m_params); ), (UfcsInherent, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); equality_typeparams(lpe.params, rpe.params); + if( lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); + this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ), (UfcsKnown, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); equality_typeparams(lpe.trait.m_params, rpe.trait.m_params); equality_typeparams(lpe.params, rpe.params); + if( lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); + this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ), (UfcsUnknown, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); // TODO: If the type is fully known, locate a suitable trait item equality_typeparams(lpe.params, rpe.params); + if( lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); + this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ) ) ), @@ -1156,7 +1162,7 @@ namespace { return true; } else { - DEBUG("- Bound " << type << " : " << trait << " failed"); + DEBUG("- Bound " << type << " ("<check_trait_bound(sp, be.type, be.trait.m_path, expand_placeholder) ) { - DEBUG("- Bound " << be.type << " : " << be.trait.m_path << " failed"); return false; } ) -- cgit v1.2.3