dotnet / dotnet/fsharp

F# compiler doesn't emit default parameter value for some types

Open
#16,112 5 comments 2 reactions 0 assignees View on GitHub
Area-Compiler-CodeGen Feature Request Needs-design
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Consider these C# and VB.NET declarations that have default parameter values:
```csharp
public class C1
{
public static void M(decimal x = 4) => Console.Write(x);
}
```
```vbnet
Public Class C2
Public Shared Sub M(Optional d As Date = #2018/01/01#)
Console.WriteLine(d)
End Sub
End Class
```

F# compiler allows using these methods without specifying values for the optional parameters:
```fsharp
C1.M()
C2.M()
```

The problem is it doesn't emit the parameter default values inside the calls, and emits type default values instead.
However, it works as expected when other allowed types are used, like `int` or `string`.
Since F# compiler allows skipping arguments for such parameters it seems that emitting the type default value, especially only for some types while working properly for others, might be a bug.

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.