F# using lazy keyword raises trimming warnings on publish.
- 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
Assessment
This issue has not been assessed yet.