| 1 |
// test object reference integrity during constructor |
| 2 |
// THANKS to Miro Swisher for discovering this issue |
| 3 |
// chuck-1.5.4.3 (ge) added Thanksgiving 2024 lol |
| 4 |
|
| 5 |
// a class definition |
| 6 |
public class Foo |
| 7 |
{ |
| 8 |
// a member function that returns `this` |
| 9 |
fun Foo getFoo() { return this; } |
| 10 |
// a constructor (takes argument for good measure) |
| 11 |
fun Foo( vec3 sz ) |
| 12 |
{ |
| 13 |
// return ourself -- note this is INSIDE Foo constructor |
| 14 |
// which means it's before this instance can be assigned |
| 15 |
// to a variable (as below); yet statements likes these |
| 16 |
// have a clean-up logic that balances reference counts; |
| 17 |
// so the refcount for Foo during instantiation must |
| 18 |
// account for this interregnum; FYI this is typically |
| 19 |
// handled by temporarily boosting the refcount during |
| 20 |
// instantiation so it cannot be deleted from within |
| 21 |
// its own constructor! |
| 22 |
this.getFoo(); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
// instantiate and assignment to variable |
| 27 |
Foo foo( @(1,2,3) ); |
| 28 |
|
| 29 |
// no crash? ok |
| 30 |
<<< "success" >>>; |