summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-11-16 10:05:55 +0800
committerJohn Hodge <tpg@mutabah.net>2016-11-16 10:05:55 +0800
commit5333e3f5d62c0d348154abccc546eeaa225c6c8f (patch)
treef71f251303c4ce36571baf2538462eb01c5c4dda /src
parent7d3fe36df2fb9af082f142f04ec3ec72a3b01f6c (diff)
downloadmrust-5333e3f5d62c0d348154abccc546eeaa225c6c8f.tar.gz
HIR Typcheck - Hackily hndle default parameters
Diffstat (limited to 'src')
-rw-r--r--src/hir_conv/bind.cpp3
-rw-r--r--src/hir_typeck/outer.cpp41
2 files changed, 41 insertions, 3 deletions
diff --git a/src/hir_conv/bind.cpp b/src/hir_conv/bind.cpp
index 91b2f038..9841a7fb 100644
--- a/src/hir_conv/bind.cpp
+++ b/src/hir_conv/bind.cpp
@@ -4,6 +4,7 @@
*
* hir_conv/bind.cpp
* - Set binding pointers in HIR structures
+ * - Also fixes parameter counts.
*/
#include "main_bindings.hpp"
#include <hir/visitor.hpp>
@@ -98,12 +99,14 @@ namespace {
void fix_type_params(const Span& sp, const ::HIR::GenericParams& params_def, ::HIR::PathParams& params)
{
+ #if 1
if( params.m_types.size() == 0 ) {
params.m_types.resize( params_def.m_types.size() );
}
if( params.m_types.size() != params_def.m_types.size() ) {
ERROR(sp, E0000, "Incorrect parameter count, expected " << params_def.m_types.size() << ", got " << params.m_types.size());
}
+ #endif
}
const ::HIR::Struct& get_struct_ptr(const Span& sp, const ::HIR::Crate& crate, ::HIR::GenericPath& path) {
diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp
index e16869bc..ef5e466f 100644
--- a/src/hir_typeck/outer.cpp
+++ b/src/hir_typeck/outer.cpp
@@ -119,8 +119,15 @@ namespace {
return rv;
}
- void update_self_type(const Span& sp, ::HIR::TypeRef& ty)
+ void update_self_type(const Span& sp, ::HIR::TypeRef& ty) const
{
+ struct H {
+ static void handle_pathparams(const Visitor& self, const Span& sp, ::HIR::PathParams& pp) {
+ for(auto& typ : pp.m_types)
+ self.update_self_type(sp, typ);
+ }
+ };
+
TU_MATCH(::HIR::TypeRef::Data, (ty.m_data), (e),
(Generic,
if(e.name == "Self") {
@@ -140,11 +147,28 @@ namespace {
(Primitive,
),
(Path,
- TODO(sp, "update_self_type - Path");
+ TU_MATCHA( (e.path.m_data), (pe),
+ (Generic,
+ H::handle_pathparams(*this, sp, pe.m_params);
+ ),
+ (UfcsKnown,
+ update_self_type(sp, *pe.type);
+ H::handle_pathparams(*this, sp, pe.trait.m_params);
+ H::handle_pathparams(*this, sp, pe.params);
+ ),
+ (UfcsInherent,
+ update_self_type(sp, *pe.type);
+ H::handle_pathparams(*this, sp, pe.params);
+ ),
+ (UfcsUnknown,
+ update_self_type(sp, *pe.type);
+ H::handle_pathparams(*this, sp, pe.params);
+ )
+ )
),
(TraitObject,
// NOTE: Can't mention Self anywhere
- TODO(sp, "update_self_type - TraitObject");
+ TODO(sp, "TraitObject - " << ty);
),
(ErasedType,
TODO(sp, "update_self_type - ErasedType");
@@ -190,6 +214,17 @@ namespace {
if( param_vals.m_types.size() != param_def.m_types.size() ) {
ERROR(sp, E0000, "Incorrect number of parameters - expected " << param_def.m_types.size() << ", got " << param_vals.m_types.size());
}
+
+ for(unsigned int i = 0; i < param_vals.m_types.size(); i ++)
+ {
+ if( param_vals.m_types[i] == ::HIR::TypeRef() ) {
+ //if( param_def.m_types[i].m_default == ::HIR::TypeRef() )
+ // ERROR(sp, E0000, "Unspecified parameter with no default");
+ // TODO: Monomorph?
+ param_vals.m_types[i] = param_def.m_types[i].m_default.clone();
+ update_self_type(sp, param_vals.m_types[i]);
+ }
+ }
// TODO: Check generic bounds
for( const auto& bound : param_def.m_bounds )