dotnet / dotnet/fsharp

Warning or error should be raised when alternative constructor calls itself

Open
#2,321 9 comments 0 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement Theme-Simple-F#
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.