Skip to content

Explicit field declaration generating property in F# classes #7

Closed
@KevinRansom

Description

@KevinRansom

Opened by: eiriktsarpalis

The definition

type Foo =
    val foo : string

currently generates the following code (decompiled):

    public class Foo
    {
        internal string foo@;
        [CompilationMapping(SourceConstructFlags.Field, 0)]
        public string foo
        {
            get
            {
                return this.foo@;
            }
        }
    }

Is this correct behaviour? It does not seem to be recorded in the documentation (http://msdn.microsoft.com/en-us/library/dd469494.aspx) or the language spec.

I should note that this goes away as soon as I add the mutable keyword in the declaration. This might be intentional, since fields are always supposed to be mutable. But this feels wrong, particularly in the context of F# where the mutable keyword comes with a declaration of intention.

comments
dsyme wrote Today at 2:16 AM [x]
Yes, this is correct. We should make it clearer in the spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions