public class Foo : Object {
	public signal void sig ();

	~Foo () {
		message ("Foo finalized");
	}
}

public class Bar : Object {
	Foo foo;

	public Bar (Foo foo) {
		this.foo = foo;
		var x = 1;
		foo.sig.connect (() => message ("Foo.sig: x = %d", x));
	}

	~Bar () {
		message ("Bar finalized");
	}
}

public class Bar2 : Object {
	Foo foo;

	public Bar2 (Foo foo) {
		this.foo = foo;
		var y = 2;
		foo.sig.connect (() => message ("Foo.sig: y = %d", y));
	}

	~Bar2 () {
		message ("Bar2 finalized");
	}
}

void do_thing_with_foo (Foo f) {
	var bar = new Bar (f);
	// bar should be finalized here
}

void main (string[] args) {
	var foo = new Foo ();
	do_thing_with_foo (foo);
	var bar2 = new Bar2 (foo);
	// only Bar2 signal handler should run since Bar should be finalized
	foo.sig ();
	// bar2 and then foo should be finalized here
}
