dotnet / dotnet/fsharp

Structured plain text formatting on private values ignore width specifiers

Open
#14,557 1 comment 0 reactions 0 assignees View on GitHub
Area-Compiler Bug good first issue help wanted Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Please provide a succinct description of the issue.

**Repro steps**

Provide the steps required to reproduce the problem:

Script:
```fsharp
type Public = { Foo: string; Bar: int }

type private Private = { Baz: string; Quux: int option }

let pub = { Foo = "hello"; Bar = 42 }
let private priv = { Baz = "world"; Quux = Some 100 }

printfn "public"
printfn $"%0A{pub}"
printfn ""
printfn "private without '+'"
printfn $"%0A{priv}"
printfn ""
printfn "private with '+'"
printfn $"%0+A{priv}
```
Run with: `dotnet fsi Repro.fsx`

**Expected behavior**

[The documentation states](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/plaintext-formatting#structured-values),
> Specifying a print width of 0 results in no print width being used. A single line of text will result, except where embedded strings in the output contain line breaks.

No fields of `priv` are embedded strings containing line breaks, therefore its string representation should be one line.

**Actual behavior**
The second group of prints, i.e. "private without '+'", spans more than one line:
```
public
{ Foo = "hello" Bar = 42 }

private without '+'
{ Baz = "world"
Quux = Some 100 }

private with '+'
{ Baz = "world" Quux = Some 100 }
```

**Known workarounds**

Add `+` to the format string.

**Related information**

Provide any related information (optional):

* Operating system: macOS 13.0.1
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 7

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.