From 08771fe5be7edded5b1cc577b3c6349a2b879946 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Thu, 9 Jul 2026 06:30:11 +0200 Subject: [PATCH] Virtual functions --- crates/codegen/src/class_decl.rs | 4 ++-- mist-test/src/items/class_test.mist | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/codegen/src/class_decl.rs b/crates/codegen/src/class_decl.rs index e17dbdb..587e91a 100644 --- a/crates/codegen/src/class_decl.rs +++ b/crates/codegen/src/class_decl.rs @@ -51,7 +51,7 @@ impl ClassProcessedData { if matches!(method.item.visibility, Visibility::Public) { match &method.item.is_override { None => { - if method.item.self_param.is_some() { + if method.item.is_virtual && method.item.self_param.is_some() { v_table.push(method.item.name.clone()); } } @@ -397,7 +397,7 @@ impl ClassProcessedData { for method in &self.methods { match method.item.visibility { Visibility::Public => { - if method.item.self_param.is_some() { + if method.item.is_virtual && method.item.self_param.is_some() { if method.item.is_override.is_none() { gen_method_point(&method.item, ctx, cg); } diff --git a/mist-test/src/items/class_test.mist b/mist-test/src/items/class_test.mist index 98d6f03..e169947 100644 --- a/mist-test/src/items/class_test.mist +++ b/mist-test/src/items/class_test.mist @@ -9,7 +9,7 @@ pub class Animal self.name = "Rex".to_string(); } - pub String speak(&self) + pub virtual String speak(&self) { "Unknown".to_string() } @@ -45,7 +45,7 @@ pub class Dog : Mammal super = Super::new(); } - pub String speak(&self) override(Animal) + pub virtual String speak(&self) override(Animal) { "Woof!".to_string() }