[Mono-bugs] [Bug 575946] New: Dynamically generated code doesn't initialize static values as expected

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Feb 1 17:33:36 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=575946

http://bugzilla.novell.com/show_bug.cgi?id=575946#c0


           Summary: Dynamically generated code doesn't initialize static
                    values as expected
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.6.x
          Platform: PC
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: misc
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: aChrisSmith at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Third Party Developer/Partner
           Blocker: ---


Description of Problem:

When executing generic code with static bindings in the F# interactive window,
the Mono runtime doesn't seem to be initializing objects correctly. This leads
to runtime crashes.

Steps to reproduce the problem:
1. Download the latest F# CTP
http://www.microsoft.com/downloads/details.aspx?FamilyID=b55f0532-ac3c-4106-918c-5586a953a7da&displaylang=en
2. Run the F# interactive console (fsi.exe)
3. Enter the following code:

--------------------
type Counter2<'a>() =
    static let x = sizeof<'a>
    static member P = x
    member this.P2 = Counter2<'a>.P
;;

let x = Counter2<int32>.P
;;

--------------------

Expected Results:

x contains the value '4'

Actual Results:

Runtime crash.

System.InvalidOperationException: The static initialization of a file or type
re
sulted in static data being accessed recursively before it was fully
initialized
.
  at Microsoft.FSharp.Core.LanguagePrimitives+IntrinsicFunctions.FailStaticInit
() [0x00000] in <filename unknown>:0
  at FSI_0002+Counter2`1[System.Int32].get_P () [0x00000] in <filename
unknown>:
0
  at <StartupCode$FSI_0003>.$FSI_0003.main@ () [0x00000] in <filename
unknown>:0

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(ob
ject,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invoke
Attr, System.Reflection.Binder binder, System.Object[] parameters,
System.Global
ization.CultureInfo culture) [0x00000] in <filename unknown>:0
Stopped due to error

How often does this happen? 

Every time.

Additional Information:

The code compiles and executes just fine, this only happens when ran through
the F# interactive window. (Which would indicate the problem lies in generics +
Reflection.Emit.)

The following console session shows the bug in action:

-----------------

C:\Program Files (x86)\FSharp-1.9.7.8\bin>type repro-5866.fs
module BugRepro

type Counter2<'a>() =
    static let x = sizeof<'a>
    static member P = x
    member this.P2 = Counter2<'a>.P

printfn "Counter2<int> = %d" (Counter2<int32>.P)
C:\Program Files (x86)\FSharp-1.9.7.8\bin>echo Compile and run repro
Compile and run repro

C:\Program Files (x86)\FSharp-1.9.7.8\bin>mono fsc.exe repro-5866.fs
Microsoft F# Compiler, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.7.8, compiling for .NET Framework Version v2.0.50727

C:\Program Files (x86)\FSharp-1.9.7.8\bin>mono repro-5866.exe
Counter2<int> = 4

C:\Program Files (x86)\FSharp-1.9.7.8\bin>echo Run same code in FSI
Run same code in FSI

C:\Program Files (x86)\FSharp-1.9.7.8\bin>mono fsi.exe

Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.7.8, compiling for .NET Framework Version v2.0.50727

For help type #help;;

> type Counter2<'a>() =
    static let x = sizeof<'a>
    static member P = x
    member this.P2 = Counter2<'a>.P
;;

type Counter2<'a> =
  class
    new : unit -> Counter2<'a>
    member P2 : int
    static member P : int
  end

>
Counter2<int32>.P
;;
System.InvalidOperationException: The static initialization of a file or type
re
sulted in static data being accessed recursively before it was fully
initialized
.
  at Microsoft.FSharp.Core.LanguagePrimitives+IntrinsicFunctions.FailStaticInit
() [0x00000] in <filename unknown>:0
  at FSI_0002+Counter2`1[System.Int32].get_P () [0x00000] in <filename
unknown>:
0
  at <StartupCode$FSI_0003>.$FSI_0003.main@ () [0x00000] in <filename
unknown>:0

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(ob
ject,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invoke
Attr, System.Reflection.Binder binder, System.Object[] parameters,
System.Global
ization.CultureInfo culture) [0x00000] in <filename unknown>:0
Stopped due to error

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list