-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
cgen: fix infix expr in method of mut receiver variable
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@[heap] | ||
struct UI {} | ||
|
||
pub fn (ui &UI) draw_rect() { | ||
println('[]') | ||
} | ||
|
||
@[heap] | ||
pub interface Node { | ||
id u64 | ||
draw() | ||
mut: | ||
ui &UI | ||
init(ui &UI) ! | ||
} | ||
|
||
@[heap] | ||
pub struct Item { | ||
pub: | ||
id u64 = 1 | ||
mut: | ||
ui &UI = unsafe { nil } | ||
body []&Node | ||
} | ||
|
||
pub fn (mut i Item) init(ui &UI) ! { | ||
assert i != unsafe { nil } // This assert generates a C gen error | ||
i.ui = ui | ||
for mut child in i.body { | ||
child.init(ui)! | ||
} | ||
} | ||
|
||
pub fn (i &Item) draw() { | ||
assert i != unsafe { nil } | ||
for child in i.body { | ||
child.draw() | ||
} | ||
} | ||
|
||
@[heap] | ||
pub struct Rectangle { | ||
Item | ||
pub mut: | ||
field f32 | ||
} | ||
|
||
pub fn (r &Rectangle) draw() { | ||
assert r != unsafe { nil } | ||
r.ui.draw_rect() | ||
r.Item.draw() | ||
} | ||
|
||
fn test_infix_expr_in_mut_receiver_method() { | ||
ui := &UI{} | ||
mut rect := &Rectangle{} | ||
|
||
rect.init(ui)! | ||
|
||
rect.draw() | ||
assert true | ||
} |