Why does this piece of code call "Search for an object of undefined type ..." when all the types used are known previously?

I am using F # 3.1 on VS2013. The following code throws the following error message

"Finding an object of undefined type based on information up to this point in the program. Before this point in the program, a type annotation may be required to restrict the type of the object. This may enable the search."

I can't figure out why this is happening as all the types used here are well known (from the .Net framework itself). Can anyone shed some light please?

open System.IO
open System.Collections.Generic

type A() as me =
    let drives = new List<DriveInfo>()

    let x = me.SelectedDrive
    let y = x.RootDirectory     // this causes "Lookup on object of indeterminate type..."

    member this.SelectedDrive with get() = drives.[0]

      

+3


source to share


1 answer


The F # compiler reads the file from top to bottom, so when the type is y

to be determined, the type this.SelectedDrive

is not yet known to the compiler. This is why you are getting this error.



+3


source







All Articles