From b19269db79d4374575b700be96873d6409c9a35c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 3 Dec 2023 21:41:48 +0800 Subject: [PATCH] AST - Parse generic types on associated type definitions --- src/ast/ast.cpp | 4 ++-- src/ast/ast.hpp | 2 +- src/parse/root.cpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 511ae0ea..a37fc4ce 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -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) { diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 2b1cf554..3111f14e 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -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 ); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 853992e8..22950ab9 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -775,9 +775,9 @@ AST::Named 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 @@ -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;