dotnet / dotnet/fsharp

`sprintf "%b" bool` causes AOT failure

Open
#17,691 4 comments 0 reactions 1 assignee Claimed by @KevinRansom View on GitHub
Area-AOT Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

`sprintf "%b" true` does not work in AOT context; nor does `sprintf "%O" true`. This affects linux-x64 8.0.401 and v9 preview 1, but not osx-arm64 8.0.300, in my testing.

**Repro steps**

In an executable with `true`:

```fsharp
let s = sprintf "%O" true // or "%b"
System.Console.WriteLine s
```

**Expected behavior**

Program prints "true".

**Actual behavior**

```
System.NotSupportedException: 'Microsoft.FSharp.Core.PrintfImpl+Specializations`3[Microsoft.FSharp.Core.Unit,System.String,System.String].CaptureFinal1[System.Boolean](Microsoft.FSharp.Core.PrintfImpl+Step[])' is missing native code.
```

**Known workarounds**

`(fun s -> $"%O{s}") true` works, as does `x.ToString () |> sprintf "%s"`.

**Related information**

Reproduced on linux-x64 with net8.0.401 and net9 preview 7, but *not* osx-arm64 8.0.300.

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.