#!/usr/local/bin/rune -x # # Test self-referential defaults in classes and compound types import "sys"; import ; alias stdio.File *stdout = stdio.stdout; int A = 1; int B = 2; int C = A + B; int D; int E; constructor void c1() { D = A + B + C; } constructor void c2() { E = D + 1; } class Fubar { # Note: constructors are called after defaults are initialized, and # are called in-order. # constructor method void c1() { this.d = this.a + this.b + this.c; } constructor method void c2() { this.e = this.d + 1; } int a = 1; int b = 2; int c = a + b; int d; int e; int no; destructor method void d1() { stdout->show("destruct #", this.no); } } int main(int ac, char **av) { Fubar fubar; stdout->show("A should be 1:", fubar.a); stdout->show("B should be 2:", fubar.b); stdout->show("C should be 3:", fubar.c); stdout->show("D should be 6:", fubar.d); stdout->show("E should be 7:", fubar.e); (int a = 1, int b = 2, int c = a + b) fubar2; stdout->show("A should be 1:", fubar2.a); stdout->show("B should be 2:", fubar2.b); stdout->show("C should be 3:", fubar2.c); stdout->show("Destruct #1 should precede Destruct #2 below:"); testfunc(); stdout->show("A(global) should be 1:", A); stdout->show("B(global) should be 2:", B); stdout->show("C(global) should be 3:", C); stdout->show("D(global) should be 6:", D); stdout->show("E(global) should be 7:", E); } void testfunc() { Fubar *a; Fubar *b; a.new(); b.new(); a->no = 1; b->no = 2; }