From 619af1e22cb71b981fde4cedbf6ebce9b3488028 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Jan 2019 00:23:07 +0300 Subject: fix AST for if expressions then is not always a block... --- crates/ra_syntax/src/ast.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast.rs') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 00c60ebf3..ab3dd1b84 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -285,13 +285,27 @@ impl LetStmt { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ElseBranchFlavor<'a> { + Block(&'a Block), + IfExpr(&'a IfExpr), +} + impl IfExpr { pub fn then_branch(&self) -> Option<&Block> { self.blocks().nth(0) } - pub fn else_branch(&self) -> Option<&Block> { - self.blocks().nth(1) + pub fn else_branch(&self) -> Option { + let res = match self.blocks().nth(1) { + Some(block) => ElseBranchFlavor::Block(block), + None => { + let elif: &IfExpr = child_opt(self)?; + ElseBranchFlavor::IfExpr(elif) + } + }; + Some(res) } + fn blocks(&self) -> AstChildren { children(self) } -- cgit v1.2.3