dotnet / dotnet/fsharp

FSI AddBoundValue should follow type forwards

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

Description

The method [`AddBoundValue()`](https://github.com/dotnet/fsharp/blob/00f1c12d7a71a2642f8594543c7d0848829e6c9b/src/fsharp/fsi/fsi.fs#L1620) doesn't follow ref->impl type forwards which can cause problems at runtime. E.g., if a `net5.0` C# app calls into this method built against `netstandard2.0` and tries to add a bound value for an `int`, you won't be able to use the imported value because FSI is using the ref assemblies, but the value from C# is from a runtime implementation assembly.

E.g.,

``` csharp
// this is C#
var x = 1;
fsi.AddBoundValue(nameof(x), x);
fsi.Eval("x + 1")
```

`fsi` will report that the types `int` and `System.Int32` aren't compatible because one type comes from `System.Private.CoreLib` and the other from `System.Runtime`.

### Workaround
When instantiating the `fsi` object, the argument `/usesdkrefs-` will enable this scenario to work.

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.