summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-11 20:55:37 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-11 20:55:37 +0800
commit75e5245e0adace314adcb457a9943fc749c22a5e (patch)
treed941025ce2e8cec6191f398779d1e34a7bc57217 /src
parent555676e4e3576d83cfe23562b686a043a4d2b81f (diff)
downloadmrust-75e5245e0adace314adcb457a9943fc749c22a5e.tar.gz
HIR Typecheck - Fields working
Diffstat (limited to 'src')
-rw-r--r--src/hir/type.cpp27
-rw-r--r--src/hir/type.hpp5
-rw-r--r--src/hir_typeck/expr.cpp5
-rw-r--r--src/hir_typeck/expr_context.cpp4
4 files changed, 27 insertions, 14 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index b57dcc7c..6e85b1aa 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -62,6 +62,12 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const
),
(Path,
os << e.path;
+ TU_MATCH(::HIR::TypeRef::TypePathBinding, (e.binding), (be),
+ (Unbound, os << "/*U*/";),
+ (Opaque, os << "/*O*/";),
+ (Struct, os << "/*S/";),
+ (Enum, os << "/*E*/";)
+ )
),
(Generic,
os << e.name << "/*";
@@ -397,18 +403,17 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
return true;
}
-namespace {
- ::HIR::TypeRef::TypePathBinding clone_binding(const ::HIR::TypeRef::TypePathBinding& x) {
- TU_MATCH(::HIR::TypeRef::TypePathBinding, (x), (e),
- (Unbound, return ::HIR::TypeRef::TypePathBinding::make_Unbound({}); ),
- (Opaque , return ::HIR::TypeRef::TypePathBinding::make_Opaque({}); ),
- (Struct , return ::HIR::TypeRef::TypePathBinding(e); ),
- (Enum , return ::HIR::TypeRef::TypePathBinding(e); )
- )
- assert(!"Fell off end of clone_binding");
- }
+::HIR::TypeRef::TypePathBinding HIR::TypeRef::TypePathBinding::clone() const {
+ TU_MATCH(::HIR::TypeRef::TypePathBinding, (*this), (e),
+ (Unbound, return ::HIR::TypeRef::TypePathBinding::make_Unbound({}); ),
+ (Opaque , return ::HIR::TypeRef::TypePathBinding::make_Opaque({}); ),
+ (Struct , return ::HIR::TypeRef::TypePathBinding(e); ),
+ (Enum , return ::HIR::TypeRef::TypePathBinding(e); )
+ )
+ assert(!"Fell off end of clone_binding");
}
+
::HIR::TypeRef HIR::TypeRef::clone() const
{
TU_MATCH(::HIR::TypeRef::Data, (m_data), (e),
@@ -424,7 +429,7 @@ namespace {
(Path,
return ::HIR::TypeRef( Data::make_Path({
e.path.clone(),
- clone_binding(e.binding)
+ e.binding.clone()
}) );
),
(Generic,
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 8a090b26..209e7f94 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -77,11 +77,14 @@ public:
// - Borrow
// - Pointer
- TAGGED_UNION(TypePathBinding, Unbound,
+ TAGGED_UNION_EX(TypePathBinding, (), Unbound, (
(Unbound, struct {}), // Not yet bound, either during lowering OR during resolution (when associated and still being resolved)
(Opaque, struct {}), // Opaque, i.e. An associated type of a generic (or Self in a trait)
(Struct, const ::HIR::Struct*),
(Enum, const ::HIR::Enum*)
+ ), (), (), (
+ TypePathBinding clone() const;
+ )
);
TAGGED_UNION(Data, Infer,
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index c090bf80..c54be433 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -146,7 +146,10 @@ namespace typeck {
(Path,
TU_MATCH(::HIR::Path::Data, (e.path.m_data), (e2),
(Generic,
- return ::HIR::TypeRef( monomorphise_genericpath_with(sp, e2, callback, allow_infer) );
+ return ::HIR::TypeRef( ::HIR::TypeRef::Data::Data_Path {
+ monomorphise_genericpath_with(sp, e2, callback, allow_infer),
+ e.binding.clone()
+ } );
),
(UfcsKnown,
return ::HIR::TypeRef( ::HIR::Path::Data::make_UfcsKnown({
diff --git a/src/hir_typeck/expr_context.cpp b/src/hir_typeck/expr_context.cpp
index 92a996a8..4a5e15a9 100644
--- a/src/hir_typeck/expr_context.cpp
+++ b/src/hir_typeck/expr_context.cpp
@@ -645,7 +645,9 @@ const ::HIR::TypeRef& typeck::TypecheckContext::expand_associated_types_to(const
return t;
}
else {
- tmp_t = this->expand_associated_types(sp, t.clone());
+ // HACK! Run twice, to expand deeper.
+ // - Should this recurse itself when it resolves?
+ tmp_t = this->expand_associated_types(sp, this->expand_associated_types(sp, t.clone()));
DEBUG("Expanded " << t << " into " << tmp_t);
return tmp_t;
}