Updated type grammar #65

This commit is contained in:
2026-06-05 17:06:06 +02:00
parent 94320bafa6
commit 40b2981252
13 changed files with 5 additions and 823 deletions
-39
View File
@@ -1,39 +0,0 @@
trait Speak {
String speak(self*);
}
struct Dog {
String name,
}
impl Speak for Dog {
String speak(self*) {
"woof".to_string()
}
}
pub void test_trait_impl() {
let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof");
}
trait Greet : Speak {
String greet(self*);
}
impl Greet for Dog {
String greet(self*) {
"hello".to_string()
}
}
pub void test_trait_with_requirement() {
let d = Dog { name: "Buddy".to_string() };
assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello");
}
pub void run_tests() {
test_trait_impl();
test_trait_with_requirement();
}