Skip to content

Commit

Permalink
AST - Parse generic types on associated type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Dec 3, 2023
1 parent 12d304a commit b19269d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ void Impl::add_function(Span sp, AttributeList attrs, bool is_public, bool is_sp
DEBUG("impl fn " << name);
m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Function(mv$(fcn)) ) } );
}
void Impl::add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, TypeRef type)
void Impl::add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, GenericParams params, TypeRef type)
{
m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Type(TypeAlias(GenericParams(), mv$(type))) ) } );
m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Type(TypeAlias(mv$(params), mv$(type))) ) } );
}
void Impl::add_static(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Static v)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class Impl
Impl& operator=(Impl&&) = default;

void add_function(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Function fcn);
void add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, TypeRef type);
void add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, GenericParams params, TypeRef type);
void add_static(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Static v);
void add_macro_invocation( MacroInvocation inv );

Expand Down
5 changes: 3 additions & 2 deletions src/parse/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,9 @@ AST::Named<AST::Item> Parse_Trait_Item(TokenStream& lex)
break; }
// Associated type
case TOK_RWORD_TYPE: {
auto atype_params = ::AST::GenericParams { };
GET_CHECK_TOK(tok, lex, TOK_IDENT);
name = tok.ident().name;
auto atype_params = Parse_GenericParamsOpt(lex);
if( GET_TOK(tok, lex) == TOK_COLON )
{
// Bounded associated type
Expand Down Expand Up @@ -1251,10 +1251,11 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl)
case TOK_RWORD_TYPE: {
GET_CHECK_TOK(tok, lex, TOK_IDENT);
auto name = tok.ident().name;
auto atype_params = Parse_GenericParamsOpt(lex);
GET_CHECK_TOK(tok, lex, TOK_EQUAL);
auto ty = Parse_Type(lex);
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
impl.add_type(lex.end_span(ps), mv$(item_attrs), is_public, is_specialisable, name, mv$(ty));
impl.add_type(lex.end_span(ps), mv$(item_attrs), is_public, is_specialisable, name, mv$(atype_params), mv$(ty));
break; }
case TOK_RWORD_UNSAFE:
fn_is_unsafe = true;
Expand Down

0 comments on commit b19269d

Please sign in to comment.