[Mono-devel-list] Bug with static field initializers

Bernie Solomon bernard at ugsolutions.com
Thu Sep 11 11:56:00 EDT 2003


The C# spec has this statement in section 10.11 on static constructors:
It is possible to construct circular dependencies that allow static fields
with variable initializers to be observed in their default value state.

And I think this is just an example of that (Trying to prove this from the
CLI spec took longer than the few minutes I have looked at this).

Bernie Solomon

----- Original Message ----- 
From: "Chris Seaton" <chris at chrisseaton.com>
To: <mono-devel-list at lists.ximian.com>
Sent: Thursday, September 11, 2003 8:23 AM
Subject: [Mono-devel-list] Bug with static field initializers


> Look at the code below. From an abstract overview you would expect it to
> print 14, but the output is 0 (it's clear why, x is initialized before
> y, so when Foo is constructed for x, y is still 0). Is this actually a
> bug, or an excepted restriction?
>
> class Foo
> {
> public int z;
>
> public Foo()
> {
> z = Bar.y;
> }
> }
>
> class Bar
> {
> public static Foo x = new Foo();
> public static int y = 14;
>
> public static void Main()
> {
> System.Console.WriteLine(x.z);
> }
> }
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list