diff options
author | John Hodge <tpg@mutabah.net> | 2016-06-13 14:49:01 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-06-13 14:49:01 +0800 |
commit | 8947b0dda71d4713c9f69c8b2cd6bde3308b5000 (patch) | |
tree | ce2f17dbf17301382e9ddbbfa47abf59d7fb4ba6 | |
parent | 2505e79b6ed4942579bf2277470aa1e00dcd0053 (diff) | |
download | mrust-8947b0dda71d4713c9f69c8b2cd6bde3308b5000.tar.gz |
HIR Typecheck - Handle monomorphising field types
-rw-r--r-- | src/hir_typeck/expr_context.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/hir_typeck/expr_context.cpp b/src/hir_typeck/expr_context.cpp index 08d8b0cd..8659e1de 100644 --- a/src/hir_typeck/expr_context.cpp +++ b/src/hir_typeck/expr_context.cpp @@ -2083,6 +2083,20 @@ bool typeck::TypecheckContext::find_field(const Span& sp, const ::HIR::TypeRef& (Struct, // Has fields! const auto& str = *be; + const auto& params = e.path.m_data.as_Generic().m_params; + auto monomorph = [&](const auto& gt)->const auto& { + const auto& ge = gt.m_data.as_Generic(); + if( ge.binding == 0xFFFF ) + TODO(sp, "Monomorphise struct field types (Self) - " << gt); + else if( ge.binding < 256 ) { + assert(ge.binding < params.m_types.size()); + return params.m_types[ge.binding]; + } + else { + BUG(sp, "function-level param encountered in struct field"); + } + return gt; + }; TU_MATCH(::HIR::Struct::Data, (str.m_data), (se), (Unit, // No fields on a unit struct @@ -2092,7 +2106,7 @@ bool typeck::TypecheckContext::find_field(const Span& sp, const ::HIR::TypeRef& { // TODO: Privacy if( FMT(i) == name ) { - field_ty = monomorphise_type_with(sp, se[i].ent, [&](const auto& gt)->const auto&{ TODO(sp, "Monomorphise tuple struct field types"); return gt; }); + field_ty = monomorphise_type_with(sp, se[i].ent, monomorph); return true; } } @@ -2102,7 +2116,7 @@ bool typeck::TypecheckContext::find_field(const Span& sp, const ::HIR::TypeRef& { // TODO: Privacy if( fld.first == name ) { - field_ty = monomorphise_type_with(sp, fld.second.ent, [&](const auto& gt)->const auto&{ TODO(sp, "Monomorphise named struct field types"); return gt; }); + field_ty = monomorphise_type_with(sp, fld.second.ent, monomorph); return true; } } |