dotnet / dotnet/fsharp

Implicit int to float conversion in function arguments fails when using arithmetic operations

Open
#17,074 13 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Overloads Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

When a function

```fsharp
let a (f: float) = f

let r0 = a 1.0
let r1 = a 1
let r2 = a (10 / 2) // Error: he type 'float' does not match the type 'int'
let r3 =
let x = 10 / 2
a x
let r4 = 10 / 2
```

It appears that implicit conversion from integer to float is not working as expected when passing an integer that is an expression involving (somehow) arithmetic operations. This behavior is inconsistent other cases (like shown in the example).

I say: The expr at `r2` should compile, too, like all other exprs.

See also here: https://twitter.com/SchlenkR/status/1781698130578211247

**Note** My experience is that this bug is a real pain for beginners, and it is extremely annoying when (e.g.) mapping values at API layers, etc.

Thanks

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.