()
| 1580 | ); |
| 1581 | } |
| 1582 | |
| 1583 | // --- Methods (`impl` blocks) and interfaces (spec 6.2 / 6.5) --- |
| 1584 | |
| 1585 | #[test] |
| 1586 | fn impl_method_static_dispatch_executes() { |
| 1587 | // `r.area()` and a method calling another method through `self` both |
| 1588 | // dispatch statically and run to the right values. |
| 1589 | assert_exit( |
| 1590 | r#" |
| 1591 | struct Rect { width: i32, height: i32 } |
| 1592 | impl Rect { |
| 1593 | area: (self: Rect*) -> i32 { return self.width * self.height } |
| 1594 | scaled_area: (self: Rect*, k: i32) -> i32 { return self.area() * k } |
| 1595 | } |
| 1596 | main: () -> i32 { |
| 1597 | r: Rect = Rect { .width = 6, .height = 7 } |
| 1598 | if r.area() != 42 { return 1 } |
| 1599 | if r.scaled_area(3) != 126 { return 2 } |
| 1600 | p: Rect* = &r |
| 1601 | if p.area() != 42 { return 3 } |
| 1602 | return 0 |
| 1603 | } |
| 1604 | "#, |
| 1605 | 0, |
| 1606 | ); |
| 1607 | } |
| 1608 | |
| 1609 | #[test] |
| 1610 | fn generic_bound_method_call_executes() { |
| 1611 | // A bounded generic specializes per concrete type; `v.describe()` resolves |
| 1612 | // to each type's own method after substitution. |
nothing calls this directly
no test coverage detected