dotnet / dotnet/fsharp

InternalsVisibleTo + internal module + inline function error message could be improved

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

Description

## Repro steps

1. Create two F# projects, `LibProject` and `TestProject`, where `TestProject` references `LibProject`
2. In `LibProject`, write the following code:
```fsharp
module internal LibProject.Tools

open System.Net
open System.Runtime.CompilerServices

[]
do ()

let inline int32FromBigEndian(num : int) =
IPAddress.NetworkToHostOrder(num)
```
3. In `TestProject`, write the following code:
```fsharp
module TestProject.Tests

open LibProject.Tools

let testTheFunction() =
let xx = int32FromBigEndian 100
0
```

The repro solution is attached: [ReproTestProject.zip](https://github.com/dotnet/fsharp/files/3355758/ReproTestProject.zip)

## Expected behavior

I think that the code should compile successfully. But even if it isn't, then the compiler should print a sensible error message.

## Actual behavior

The code doesn't compile and the compiler provides rather cryptic messages:

```
LibProject\LibProject.fs(9,12): Error FS1113 : The value 'int32FromBigEndian' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
TestProject\TestProject.fs(6,14): Warning FS1116 : A value marked as 'inline' has an unexpected value
TestProject\TestProject.fs(6,14): Error FS1118 : Failed to inline the value 'int32FromBigEndian' marked 'inline', perhaps because a recursive value was marked 'inline'
```

## Known workarounds

Well, don't use inline functions within internal modules with the `InternalsVisibleTo` attribute :)

## Related information

Reproduced using .NET Core SDK:

```
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.300
Commit: 73efd5bd87

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.300\

Host (useful for support):
Version: 2.2.5
Commit: 0a3c9209c0
```

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.