diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-28 19:45:36 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-28 19:45:36 +0800 |
commit | 00b321213756480775a9cf369bbf715c7e546cd0 (patch) | |
tree | cb8c1f0cf5994fc80655ea2a16350a12273d0293 /src | |
parent | 8c8869627ed1373f4e8e5af8550f37d07bdd71c1 (diff) | |
download | mrust-00b321213756480775a9cf369bbf715c7e546cd0.tar.gz |
HIR Conv Type Aliases - Handle parameters (hackily, same as rustc)
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_conv/expand_type.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/hir_conv/expand_type.cpp b/src/hir_conv/expand_type.cpp index 76349ff8..ff00743d 100644 --- a/src/hir_conv/expand_type.cpp +++ b/src/hir_conv/expand_type.cpp @@ -5,6 +5,7 @@ #include <hir/hir.hpp> #include <hir/expr.hpp> #include <hir/visitor.hpp> +#include <hir_typeck/common.hpp> // monomorphise_type_with ::HIR::TypeRef ConvertHIR_ExpandAliases_GetExpansion(const ::HIR::Crate& crate, const ::HIR::Path& path) { @@ -17,10 +18,29 @@ // Anything else - leave it be ), (TypeAlias, + if( e.m_params.m_types.size() != e2.m_params.m_types.size() ) { + ERROR(sp, E0000, "Mismatched parameter count in " << path); + } if( e2.m_params.m_types.size() > 0 ) { - TODO(Span(), "Replace type params in type alias"); + // TODO: Better `monomorphise_type` + return monomorphise_type_with(sp, e2.m_type, [&](const auto& gt)->const auto& { + const auto& ge = gt.m_data.as_Generic(); + if( ge.binding == 0xFFFF ) { + BUG(sp, "Self encountered in expansion for " << path << " - " << e2.m_type); + } + else if( (ge.binding >> 8) == 0 ) { + auto idx = ge.binding & 0xFF; + ASSERT_BUG(sp, idx < e.m_params.m_types.size(), ""); + return e.m_params.m_types[idx]; + } + else { + BUG(sp, "Bad index " << ge.binding << " encountered in expansion for " << path << " - " << e2.m_type); + } + }); + } + else { + return e2.m_type.clone(); } - return e2.m_type.clone(); ) ) ), |