Skip to content

Commit

Permalink
Fix implement #31
Browse files Browse the repository at this point in the history
  • Loading branch information
nilq committed Jul 7, 2020
1 parent b491949 commit c038489
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Cargo.lock
**/*.rs.bk

/target/
**/*.rs.bk
**/*.rs.bk
2 changes: 1 addition & 1 deletion src/wu/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
24 changes: 23 additions & 1 deletion src/wu/visitor/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -619,6 +630,12 @@ impl<'v> Visitor<'v> {
));
}
}
} else {
return Err(response!(
Wrong(format!("can't implement type `{}`", kind)),
self.source.file,
expr.pos
))
}
}
}
Expand Down Expand Up @@ -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) =
Expand Down

0 comments on commit c038489

Please sign in to comment.