From c03848937c7f65536691369bab3cb6a2de86bfd5 Mon Sep 17 00:00:00 2001 From: nilq Date: Tue, 7 Jul 2020 13:21:20 +0200 Subject: [PATCH] Fix implement #31 --- .gitignore | 2 +- src/wu/parser/parser.rs | 2 +- src/wu/visitor/visitor.rs | 24 +++++++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d73bada..69e53a3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ Cargo.lock **/*.rs.bk /target/ -**/*.rs.bk +**/*.rs.bk \ No newline at end of file diff --git a/src/wu/parser/parser.rs b/src/wu/parser/parser.rs index 5fd1274..c6a3c9a 100644 --- a/src/wu/parser/parser.rs +++ b/src/wu/parser/parser.rs @@ -253,7 +253,7 @@ impl<'p> Parser<'p> { let start = self.index; - while !["{", ":"].contains(&self.current_lexeme().as_str()) + while self.current_type() == TokenType::Identifier && self.remaining() > 1 { self.next()?; diff --git a/src/wu/visitor/visitor.rs b/src/wu/visitor/visitor.rs index 98ae415..d558912 100644 --- a/src/wu/visitor/visitor.rs +++ b/src/wu/visitor/visitor.rs @@ -90,6 +90,9 @@ impl TypeNode { (&Struct(ref name, _, ref content), &Struct(ref name_b, _, ref content_b)) => { name == name_b && content == content_b } + (&Trait(ref name, ref content), &Trait(ref name_b, ref content_b)) => { + name == name_b && content == content_b + } _ => false, } } @@ -601,7 +604,15 @@ impl<'v> Visitor<'v> { if let TypeNode::Struct(_, ref content, _) = self.fetch(&struct_name, &position)?.node { - if let TypeNode::Trait(_, ref content_b) = trait_ty.node { + if let TypeNode::Trait(ref n, ref content_b) = trait_ty.node { + if let TypeNode::Struct(_, _, _) = trait_ty.node { + return Err(response!( + Wrong(format!("can't implement type `{}`", kind)), + self.source.file, + position + )) + } + for (name, ty) in content_b.iter() { if let Some(ty_b) = content.get(name) { if ty.node != ty_b.node { @@ -619,6 +630,12 @@ impl<'v> Visitor<'v> { )); } } + } else { + return Err(response!( + Wrong(format!("can't implement type `{}`", kind)), + self.source.file, + expr.pos + )) } } } @@ -2455,6 +2472,11 @@ impl<'v> Visitor<'v> { for (i, statement) in ast.iter().enumerate() { // don't visit function bodies + + if let StatementNode::Expression(Expression { node: ExpressionNode::EOF, .. }) = statement.node { + continue + } + if let StatementNode::Variable(_, ref name, ref right) = statement.node { if let Some(ref right) = *right { if let ExpressionNode::Function(ref params, ref retty, .., is_method) =