Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Question about changed behavior of string interpolations in NativeAOT in the .NET 11 rc1 SDK

Đang mở
#20,757 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@T-Gro đang làm issue này rồi.

Từ ngày 13/10/2026.

  • #20778 của @T-Gro — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
fsharp
Lĩnh vực
compilers

Hướng nghiên cứu

The regression is in how the F# compiler lowers interpolated strings with format specifiers, so start from the interpolated-string lowering code and compare the .NET 10 and .NET 11 rc1 output for %02d in the fsharp repo. Reproduce with the NativeAOT snippet from the issue, then check the IL or decompiled output for the PrintFormatToString call shape. Done means the interpolated string runs under NativeAOT again, or a maintainer decides the change is intended and documents it. This is a compiler regression with no clear fix direction, so it is not a good first issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug

Hi,

Not sure if this is a bug, or an expected change after https://github.com/dotnet/fsharp/pull/19971, but as it came across as a breaking change to me I'll ask in case.

When doing testing with https://github.com/fable-hub/Scriptorium/pull/21 I noticed that if I have the code

let now = System.DateTime.UtcNow

let startAt =
    $"%02d{now.Hour}:%02d{now.Minute}:%02d{now.Second}"

and compile that with NativeAOT using the .NET 10 SDK then the resulting executable works correctly, but compiling the same code with the .NET11-RC1 SDK then it crashes at runtime with an exception similar to the one in https://github.com/fable-hub/Scriptorium/pull/21.

This doesn't seem ideal, even given the known issues with F# style format specifiers, if it worked before and doesn't now?

fwiw, looking at the binary with ILSpy, the .NET 10 build that works decompiles as

string startAt2 = (startAt2@10 = ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<string, Unit, string, string, Tuple<int, int, int>>("%02d%P():%02d%P():%02d%P()", new object[3]
{
    Program.now.Hour,
    Program.now.Minute,
    Program.now.Second
}, null)));

and the .NET 11 build that doesn't shows as

string startAt2 = (startAt2@9 = ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Hour) + ":" + ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Minute) + ":" + ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Second));

Known workarounds

Doing $"{now.Hour:D2}:{now.Minute:D2}:{now.Second:D2}" works in the RC1 SDK, so it can at least be made to work that way.

Thanks.

Ngôn ngữ chính
F#
Star
4.3k
Fork
880
Merge trung bình
3 ngày 21 giờ
Pull request đã merge (30 ngày)
109

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/fsharp

Tất cả issue của dotnet/fsharp

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.