dotnet / dotnet/fsharp

F# using lazy keyword raises trimming warnings on publish.

Open
#17,355 1 comment 1 reaction 1 assignee Claimed by @KevinRansom View on GitHub
Area-AOT Bug Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

### Discussed in https://github.com/dotnet/fsharp/discussions/17323

Originally posted by **@abklearnhere** June 18, 2024
F# using lazy keyword raises trimming warnings on publish. For example,
```fsharp
let f23 () = let z = lazy (12345) in z.Force()
[]
let main _ =
f23() |> System.Console.WriteLine
0
```
I am creating an F#, .NET 8 (SDK 8.0.302) console app and publish as a single file with AOT, trimming. I run dotnet publish command as below:
```powershell
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishAot=true -p:PublishTrimmed=true -p:ReflectionFree=false -o ./publish
```
This results in warning:
>D:\a\_work\1\s\src\FSharp.Core\prim-types.fs(7159): Trim analysis warning **IL2091**: Microsoft.FSharp.Control.LazyExtensions.Create(FSharpFunc\`2): 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'System.Lazy\`1'. The generic parameter 'T' of 'Micros
oft.FSharp.Control.LazyExtensions.Create(FSharpFunc\`2)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

The warning appears regardless of `-p:ReflectionFree` being false or true. The `fsproj` file has following settings:
```xml
Exe
net8.0
true
true
true
false
```

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.