diff options
author | John Hodge <tpg@ucc.asn.au> | 2016-06-09 21:46:45 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2016-06-09 21:46:45 +0800 |
commit | dee263533dbc77a65baa796c6414819da36bc3ce (patch) | |
tree | 3d22820da91c41d6587b798e0cbcdf50aa516cf4 /src | |
parent | 01d97106b9977f5f0226b4c446616f195fbeaaf4 (diff) | |
download | mrust-dee263533dbc77a65baa796c6414819da36bc3ce.tar.gz |
HIR Typecheck - Associated type bounds used and "working"
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr.cpp | 25 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 2 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 7b538480..c186272e 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -1236,12 +1236,27 @@ namespace { const auto& trait_ptr = this->m_crate.get_trait_by_path(sp, pe.trait.m_path); const auto& assoc_ty = trait_ptr.m_types.at(pe.item); DEBUG("TODO: Search bounds " << assoc_ty.m_params.fmt_bounds()); - auto cb_placeholders = [&](const auto& ty)->const auto&{ + // Resolve where Self=e2.type, for the associated type check. + auto cb_placeholders_type = [&](const auto& ty)->const auto&{ TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Generic, e, if( e.binding == 0xFFFF ) return *e2.type; else - TODO(sp, "Handle type pareters when expanding associated bound"); + TODO(sp, "Handle type params when expanding associated bound (#" << e.binding << " " << e.name); + ) + else { + return ty; + } + }; + // Resolve where Self=pe.type (i.e. for the trait this inner UFCS is on) + auto cb_placeholders_trait = [&](const auto& ty)->const auto&{ + TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Generic, e, + if( e.binding == 0xFFFF ) + return *pe.type; + else { + // TODO: Look in pe.trait.m_params + TODO(sp, "Handle type params when expanding associated bound (#" << e.binding << " " << e.name); + } ) else { return ty; @@ -1252,9 +1267,11 @@ namespace { TU_IFLET(::HIR::GenericBound, bound, TypeEquality, be, // IF: bound's type matches the input, replace with bounded equality // `<Self::IntoIter as Iterator>::Item = Self::Item` - if( be.type.compare_with_paceholders(sp, input, cb_placeholders ) ) { + if( be.type.compare_with_paceholders(sp, input, cb_placeholders_type ) ) { + DEBUG("Match of " << be.type << " with " << input); + DEBUG("- Replace `input` with " << be.other_type << ", Self=" << *pe.type); if( monomorphise_type_needed(be.other_type) ) { - TODO(sp, "Monomorphise associated type replacment"); + return monomorphise_type_with(sp, be.other_type, cb_placeholders_trait); } else { return be.other_type.clone(); diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index f224d5f9..393120b9 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -20,7 +20,7 @@ struct GenericSlot unsigned short index; unsigned int to_binding() const { - if(level == Level::Method) { + if(level == Level::Method && index != 0xFFFF) { return (unsigned int)index + 256; } else { |