Skip to content

Warning or error should be raised when alternative constructor calls itself #2321

@markpattison

Description

@markpattison

The language spec (8.6.3) says that any additional constructor should call another constructor.

It's possible for an additional constructor to call itself (presumably accidentally on the part of the programmer), which results in a stack overflow.

Repro steps

type MyClass(a, b) =
    new(a) = MyClass(a)

let x = MyClass(1)

Expected behavior

Compiler should issue a warning or error when a constructor calls itself.

Actual behavior

StackOverflowException is thrown.

Known workarounds

N/A

Related information

Windows 7, F#4.0, .NET 4.5.2
Severity = low

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsFeature ImprovementTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions