diff --git a/crates/codegen/src/class_decl.rs b/crates/codegen/src/class_decl.rs index 85b8591..9938d0b 100644 --- a/crates/codegen/src/class_decl.rs +++ b/crates/codegen/src/class_decl.rs @@ -51,7 +51,9 @@ impl ClassProcessedData { if matches!(method.item.visibility, Visibility::Public) { match &method.item.is_override { None => { - v_table.push(method.item.name.clone()); + if method.item.is_using_self() { + v_table.push(method.item.name.clone()); + } } Some(override_spec) => { override_v_table @@ -412,18 +414,7 @@ impl ClassProcessedData { for method in &self.methods { match method.item.visibility { Visibility::Public => { - let is_using_self = match method.item.params.0.get(0) { - Some(VarDecl { name, .. }) => { - if let Pattern::Path(_, v) = name { - v.0.len() == 1 && v.0[0].0 == "self" - } else { - false - } - } - _ => false, - }; - - if is_using_self { + if method.item.is_using_self() { if method.item.is_override.is_none() { gen_method_point(&method.item, ctx, cg); } diff --git a/crates/parser/src/ast/top_level.rs b/crates/parser/src/ast/top_level.rs index be4a4b3..2899893 100644 --- a/crates/parser/src/ast/top_level.rs +++ b/crates/parser/src/ast/top_level.rs @@ -125,3 +125,18 @@ pub struct FieldDeclStmt { pub decl: FieldDecl, pub init: Option, } + +impl FunctionDecl { + pub fn is_using_self(&self) -> bool { + match self.params.0.get(0) { + Some(VarDecl { name, .. }) => { + if let Pattern::Path(_, v) = name { + v.0.len() == 1 && v.0[0].0 == "self" + } else { + false + } + } + _ => false, + } + } +} diff --git a/mist-test/src/items/class_test.mist b/mist-test/src/items/class_test.mist index 7284982..8c441e4 100644 --- a/mist-test/src/items/class_test.mist +++ b/mist-test/src/items/class_test.mist @@ -15,6 +15,8 @@ pub class Animal { pub fn test_speak(*self) { self.speak(); } + + pub fn static_method() {} } pub class Mammal : Animal {