summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/types.cpp16
-rw-r--r--src/ast/types.hpp12
-rw-r--r--src/hir_typeck/expr.cpp1
-rw-r--r--src/resolve/absolute.cpp31
4 files changed, 36 insertions, 24 deletions
diff --git a/src/ast/types.cpp b/src/ast/types.cpp
index 7b1c4cdb..070f02ba 100644
--- a/src/ast/types.cpp
+++ b/src/ast/types.cpp
@@ -168,16 +168,6 @@ Ordering TypeRef::ord(const TypeRef& x) const
return OrdEqual;
),
(Generic,
- if( ent.params != x_ent.params )
- {
- DEBUG(*this << " == " << x);
- if( ent.params ) DEBUG("- (L) " << *ent.params);
- if( x_ent.params ) DEBUG("- (R) " << *x_ent.params);
- throw ::std::runtime_error("Can't compare mismatched generic types");
- //BUG(m_span, "Can't compare mismatched generic types");
- }
- else {
- }
return ::ord(ent.name, x_ent.name);
),
(Path,
@@ -245,7 +235,7 @@ Ordering TypeRef::ord(const TypeRef& x) const
os << "]";
)
_(Generic,
- os << "/* arg */ " << ent.name << "/*"<<ent.level<<"*/";
+ os << "/* arg */ " << ent.name << "/*"<<ent.index<<"*/";
)
_(Path,
os << ent.path;
@@ -337,7 +327,7 @@ SERIALISE_TYPE(TypeRef::, "TypeRef", {
)
_S(Generic,
s.item( ent.name );
- s.item( ent.level );
+ s.item( ent.index );
)
_S(Array,
s.item( ent.inner );
@@ -386,7 +376,7 @@ SERIALISE_TYPE(TypeRef::, "TypeRef", {
)
_D(Generic,
s.item( ent.name );
- s.item( ent.level );
+ s.item( ent.index );
)
_D(Array,
s.item( ent.inner );
diff --git a/src/ast/types.hpp b/src/ast/types.hpp
index 2e9608a5..4ffff312 100644
--- a/src/ast/types.hpp
+++ b/src/ast/types.hpp
@@ -88,8 +88,7 @@ TAGGED_UNION(TypeData, None,
}),
(Generic, struct {
::std::string name;
- unsigned int level;
- const ::AST::GenericParams* params;
+ unsigned int index;
}),
(Path, struct {
AST::Path path;
@@ -194,10 +193,7 @@ public:
struct TagArg {};
TypeRef(TagArg, ::std::string name):
- m_data(TypeData::make_Generic({ name, 0, nullptr }))
- {}
- TypeRef(TagArg, ::std::string name, const AST::GenericParams& params):
- m_data(TypeData::make_Generic({ name, 0, &params }))
+ m_data(TypeData::make_Generic({ name, 0 }))
{}
TypeRef(::std::string name):
TypeRef(TagArg(), ::std::move(name))
@@ -234,10 +230,6 @@ public:
bool is_type_param() const { return m_data.is_Generic(); }
const ::std::string& type_param() const { return m_data.as_Generic().name; }
- void set_type_params_ptr(const AST::GenericParams& p) { m_data.as_Generic().params = &p; };
- const AST::GenericParams* type_params_ptr() const {
- return reinterpret_cast<const AST::GenericParams*>( m_data.as_Generic().params );
- }
bool is_reference() const { return m_data.is_Borrow(); }
bool is_pointer() const { return m_data.is_Pointer(); }
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index 7b22f9d3..f0a2cee1 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -888,6 +888,7 @@ namespace {
// ------------------
if( node_ptr_ptr != nullptr )
{
+ // TODO: Allow cases where `right`: ::core::ops::Unsize<`left`>
// - If left is a trait object, right can unsize
// - If left is a slice, right can unsize/deref
if( l_e.inner->m_data.is_Slice() && !r_e.inner->m_data.is_Slice() )
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index 180cab0f..86d35ca7 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -68,6 +68,7 @@ struct Context
if( has_self ) {
assert( level == GenericSlot::Level::Top );
data.types.push_back( Named<GenericSlot> { "Self", GenericSlot { level, 0xFFFF } } );
+ m_name_context.push_back( Ent::make_ConcreteSelf(nullptr) );
}
if( params.ty_params().size() > 0 ) {
const auto& typs = params.ty_params();
@@ -106,6 +107,25 @@ struct Context
BUG(Span(), "resolve/absolute.cpp - Context::pop(TypeRef) - Mismatched pop");
}
}
+ ::TypeRef get_self() const {
+ for(auto it = m_name_context.rbegin(); it != m_name_context.rend(); ++ it)
+ {
+ TU_MATCH_DEF(Ent, (*it), (e),
+ (
+ ),
+ (ConcreteSelf,
+ if( e ) {
+ return e->clone();
+ }
+ else {
+ return ::TypeRef("Self");
+ }
+ )
+ )
+ }
+
+ TODO(Span(), "Error when get_self called with no self");
+ }
void push_block() {
m_block_level += 1;
@@ -815,7 +835,16 @@ void Resolve_Absolute_Type(Context& context, TypeRef& type)
}
),
(Generic,
- // TODO: Should this be bound to the relevant index, or just leave as-is?
+ if( e.name == "Self" )
+ {
+ type = context.get_self();
+ }
+ else
+ {
+ auto idx = context.lookup_local(type.span(), e.name, Context::LookupMode::Type);
+ // TODO: Should this be bound to the relevant index, or just leave as-is?
+ e.index = idx;
+ }
),
(Path,
Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, e.path);