Files
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

36 lines
890 B
Mojo

# probe: a trait with a default method, used by two structs
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
# expect-stdout: a shape of area 7.0
# expect-stdout: a square of side 4.0
trait Shape:
def area(self) -> Float64:
...
def describe(self) -> String:
return "a shape of area " + String(self.area())
@fieldwise_init
struct Rect(Shape, Copyable, Movable):
var w: Float64
var h: Float64
def area(self) -> Float64:
return self.w * self.h
@fieldwise_init
struct Square(Shape, Copyable, Movable):
var side: Float64
def area(self) -> Float64:
return self.side * self.side
def describe(self) -> String:
return "a square of side " + String(self.side)
def main():
print(Rect(2.0, 3.5).describe())
print(Square(4.0).describe())