diff options
-rw-r--r-- | src/ast/types.cpp | 3 | ||||
-rw-r--r-- | src/expand/mod.cpp | 42 | ||||
-rw-r--r-- | src/hir/from_ast.cpp | 11 |
3 files changed, 50 insertions, 6 deletions
diff --git a/src/ast/types.cpp b/src/ast/types.cpp index d49feccd..f2387068 100644 --- a/src/ast/types.cpp +++ b/src/ast/types.cpp @@ -122,7 +122,8 @@ TypeRef TypeRef::clone() const _COPY(None) _COPY(Any) _COPY(Bang) - case TypeData::TAG_Macro: assert( !"Copying an unexpanded type macro" ); + _CLONE(Macro, { old.inv.clone() }) + //case TypeData::TAG_Macro: assert( !"Copying an unexpanded type macro" ); _COPY(Unit) _COPY(Primitive) _COPY(Function) diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 629020a7..adc53bf4 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -824,6 +824,40 @@ void Expand_Expr(::AST::Crate& crate, LList<const AST::Module*> modstack, AST::E } } +void Expand_GenericParams(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST::Module& mod, ::AST::GenericParams& params) +{ + for(auto& ty_def : params.ty_params()) + { + Expand_Type(crate, modstack, mod, ty_def.get_default()); + } + for(auto& bound : params.bounds()) + { + TU_MATCHA( (bound), (be), + (Lifetime, + ), + (TypeLifetime, + Expand_Type(crate, modstack, mod, be.type); + ), + (IsTrait, + Expand_Type(crate, modstack, mod, be.type); + Expand_Path(crate, modstack, mod, be.trait); + ), + (MaybeTrait, + Expand_Type(crate, modstack, mod, be.type); + Expand_Path(crate, modstack, mod, be.trait); + ), + (NotTrait, + Expand_Type(crate, modstack, mod, be.type); + Expand_Path(crate, modstack, mod, be.trait); + ), + (Equality, + Expand_Type(crate, modstack, mod, be.type); + Expand_Type(crate, modstack, mod, be.replacement); + ) + ) + } +} + void Expand_BareExpr(const ::AST::Crate& crate, const AST::Module& mod, ::std::unique_ptr<AST::ExprNode>& node) { Expand_Expr(const_cast< ::AST::Crate&>(crate), LList<const AST::Module*>(nullptr, &mod), node); @@ -836,6 +870,7 @@ void Expand_Impl(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST: DEBUG("Deleted"); return ; } + Expand_GenericParams(crate, modstack, mod, impl.def().params()); Expand_Type(crate, modstack, mod, impl.def().type()); //Expand_Type(crate, modstack, mod, impl.def().trait()); @@ -916,6 +951,7 @@ void Expand_ImplDef(::AST::Crate& crate, LList<const AST::Module*> modstack, ::A DEBUG("Deleted"); return ; } + Expand_GenericParams(crate, modstack, mod, impl_def.params()); Expand_Type(crate, modstack, mod, impl_def.type()); //Expand_Type(crate, modstack, mod, impl_def.trait()); @@ -1006,6 +1042,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: ), (Struct, + Expand_GenericParams(crate, modstack, mod, e.params()); TU_MATCH(AST::StructData, (e.m_data), (sd), (Unit, ), @@ -1038,6 +1075,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: ) ), (Enum, + Expand_GenericParams(crate, modstack, mod, e.params()); for(auto& var : e.variants()) { Expand_Attrs(var.m_attrs, AttrStage::Pre, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, var); }); TU_MATCH(::AST::EnumVariantData, (var.m_data), (e), @@ -1067,6 +1105,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: } ), (Union, + Expand_GenericParams(crate, modstack, mod, e.m_params); for(auto it = e.m_variants.begin(); it != e.m_variants.end(); ) { auto& si = *it; Expand_Attrs(si.m_attrs, AttrStage::Pre, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); }); @@ -1080,6 +1119,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: } ), (Trait, + Expand_GenericParams(crate, modstack, mod, e.params()); for(auto& ti : e.items()) { auto attrs = mv$(ti.data.attrs); @@ -1091,6 +1131,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: ), (None, ), (Function, + Expand_GenericParams(crate, modstack, mod, e.params()); for(auto& arg : e.args()) { Expand_Pattern(crate, modstack, mod, arg.first, false); Expand_Type(crate, modstack, mod, arg.second); @@ -1117,6 +1158,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: ), (Function, + Expand_GenericParams(crate, modstack, mod, e.params()); for(auto& arg : e.args()) { Expand_Pattern(crate, modstack, mod, arg.first, false); Expand_Type(crate, modstack, mod, arg.second); diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 96cd4725..b4ea38e6 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -69,12 +69,13 @@ rv.m_bounds.back().as_TraitBound().trait.m_hrls = e.hrls; ), (MaybeTrait, - if( ! e.type.m_data.is_Generic() ) - BUG(bound.span, "MaybeTrait on non-param"); - const auto& ge = e.type.m_data.as_Generic(); + auto type = LowerHIR_Type(e.type); + if( ! type.m_data.is_Generic() ) + BUG(bound.span, "MaybeTrait on non-param - " << type); + const auto& ge = type.m_data.as_Generic(); const auto& param_name = ge.name; unsigned param_idx; - if( ge.index == 0xFFFF ) { + if( ge.binding == 0xFFFF ) { if( !self_is_sized ) { BUG(bound.span, "MaybeTrait on parameter on Self when not allowed"); } @@ -83,7 +84,7 @@ else { param_idx = ::std::find_if( rv.m_types.begin(), rv.m_types.end(), [&](const auto& x) { return x.m_name == param_name; } ) - rv.m_types.begin(); if( param_idx >= rv.m_types.size() ) { - BUG(bound.span, "MaybeTrait on parameter not in parameter list (#" << ge.index << " " << param_name << ")"); + BUG(bound.span, "MaybeTrait on parameter not in parameter list (#" << ge.binding << " " << param_name << ")"); } } |