ast: Add the "Self" type in preparation for cl-typeck

This commit is contained in:
John 2024-02-27 22:48:24 -06:00
parent e3f08ac013
commit 5484d96e7d
3 changed files with 6 additions and 0 deletions

View File

@ -187,6 +187,7 @@ pub struct Ty {
pub enum TyKind { pub enum TyKind {
Never, Never,
Empty, Empty,
SelfTy,
Path(Path), Path(Path),
Tuple(TyTuple), Tuple(TyTuple),
Ref(TyRef), Ref(TyRef),

View File

@ -214,6 +214,7 @@ mod display {
match &self.kind { match &self.kind {
TyKind::Never => "!".fmt(f), TyKind::Never => "!".fmt(f),
TyKind::Empty => "()".fmt(f), TyKind::Empty => "()".fmt(f),
TyKind::SelfTy => "Self".fmt(f),
TyKind::Path(v) => v.fmt(f), TyKind::Path(v) => v.fmt(f),
TyKind::Tuple(v) => v.fmt(f), TyKind::Tuple(v) => v.fmt(f),
TyKind::Ref(v) => v.fmt(f), TyKind::Ref(v) => v.fmt(f),

View File

@ -676,6 +676,10 @@ impl<'t> Parser<'t> {
self.consume_peeked(); self.consume_peeked();
TyKind::Never TyKind::Never
} }
Type::Keyword(Keyword::SelfTy) => {
self.consume_peeked();
TyKind::SelfTy
}
Type::Amp | Type::AmpAmp => self.tyref()?.into(), Type::Amp | Type::AmpAmp => self.tyref()?.into(),
Type::LParen => self.tytuple()?.into(), Type::LParen => self.tytuple()?.into(),
Type::Keyword(Keyword::Fn) => self.tyfn()?.into(), Type::Keyword(Keyword::Fn) => self.tyfn()?.into(),