dotnet / dotnet/fsharp

Calling op_Addition on primitive types doesn't work

Open
#14,013 1 comment 0 reactions 0 assignees View on GitHub
Bug Impact-Low Resolution-By Design
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Calling op_Addition on primitive types doesn't work but works on new BCL types.

**Repro steps**

```
> System.Int32.op_Addition (3, 6) ;;

System.Int32.op_Addition (3, 6) ;;
-------------^^^^^^^^^^^

C:\Repos\stdin(3,14): error FS0039: The type 'Int32' does not define the field, constructor or member '+'.
```

but

```
> System.Int128.op_Addition (3, 6) ;;
val it: System.Int128 = 9
```

**Expected behavior**

Same in both cases

**Actual behavior**

The former doesn't work, the latter does.

**Known workarounds**

Don't do it.

**Related information**

In case this is somehow expected we need to document this in the RFC.
Also I wonder if the definition of standard F# operators is adapted in order to work on new BCL interfaces like `IAdditionOperators`, it seems they are not, which means if I define my own type implementing `IAdditionOperators` I won't be able to just use F# standard `+` operator, without having to redefine it. The RFC doesn't mention about adjusting existing math operators, maybe it should clarify.

Microsoft (R) F# Interactive version 12.0.5.0 for F# 7.0

Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.4.0 Preview 2.1

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.