lang: for-loop over List(T); deref a *T method receiver
The collection for-loop now iterates a List(T)-like struct ({ items: [*]T, len, … }) — and a *List — by viewing it as items[0..len]. So 'for legal: (m)' / 'for pieces: (*p)' work like iterating a slice, with by-ref captures writing back into the backing.
fixupMethodReceiver also derefs a *T receiver when the method takes T by value, so a 'for xs: (*x)' capture can call value-self methods (x.method()). Regression: examples/for-list.sx.
This commit is contained in:
1
tests/expected/for-list.exit
Normal file
1
tests/expected/for-list.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
4
tests/expected/for-list.txt
Normal file
4
tests/expected/for-list.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
sum 60
|
||||
sum2 360
|
||||
via ptr 360
|
||||
boxes 7
|
||||
Reference in New Issue
Block a user