Skip to content

Compiler emits incorrect visibility modifier for internal constructors of abstract class #420

@axel-habermaier

Description

@axel-habermaier

Compile the following code:

[<AbstractClass>]
type X internal (i : int) =
    internal new () = X 1
    new (f : float32) = X 1

Note that we've defined an abstract class with two internal constructors and one public one. When you disassemble the code you can see that the following code was generated by the compiler:

[AbstractClass]
[CompilationMapping(SourceConstructFlags.ObjectType)]
[Serializable]
public abstract class X
{
    protected X(int i)
    {
      base..ctor();
      Program.X x = this;
    }

    protected X()
    {
      this..ctor(1);
    }

    protected X(float f)
    {
      this..ctor(1);
    }
}

Note how the constructors' visibilities were incorrectly changed to protected; that's only ok for the public constructor, but definitely wrong for the internal ones. The internal constructors should still be internal. I noticed that problem while deriving from such a class in a C# project where all of a sudden I had the possibility to choose between different base constructors to call, whereas only the public one of the F# class should have been visible.

Happens with VS2013 and VS2015 RC in both debug and release builds. When you remove the [<AbstractClass>] attribute, the compiler emits the correct visibilities.

I realize that fixing this bug would be a breaking change, but then again, I consider this bug to be pretty serious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions