From a0ecaa644c259e82a4aa85c57bc409a228e1ba07 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 12:59:40 +0000 Subject: [PATCH 1/4] Initial plan From 4cf01849e0e453892ec8935d71c0e379d6749ffd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 13:24:36 +0000 Subject: [PATCH 2/4] Fix internal error when using custom attribute with optional value type argument (fixes #8353) Handle Const.Zero for all primitive value types in GenAttribArg, which is used when [] is specified without [] on attribute constructor parameters. Previously only System.Object, System.String, and System.Type were handled, causing an internal error for bool, int, and other value types. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/6f81842d-a307-4b7e-9ef2-ffa78948f9c6 --- src/Compiler/CodeGen/IlxGen.fs | 12 +++++ .../CustomAttributes/Basic/Basic.fs | 8 ++++ .../Basic/OptionalAttributeArgs.fs | 48 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 14a966ad068..c410291db48 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -10217,6 +10217,18 @@ and GenAttribArg amap g eenv x (ilArgTy: ILType) = | Const.Zero when isobj -> ILAttribElem.Null | Const.Zero when tynm = "System.String" -> ILAttribElem.String None | Const.Zero when tynm = "System.Type" -> ILAttribElem.Type None + | Const.Zero when tynm = "System.Boolean" -> ILAttribElem.Bool false + | Const.Zero when tynm = "System.SByte" -> ILAttribElem.SByte 0y + | Const.Zero when tynm = "System.Int16" -> ILAttribElem.Int16 0s + | Const.Zero when tynm = "System.Int32" -> ILAttribElem.Int32 0 + | Const.Zero when tynm = "System.Int64" -> ILAttribElem.Int64 0L + | Const.Zero when tynm = "System.Byte" -> ILAttribElem.Byte 0uy + | Const.Zero when tynm = "System.UInt16" -> ILAttribElem.UInt16 0us + | Const.Zero when tynm = "System.UInt32" -> ILAttribElem.UInt32 0u + | Const.Zero when tynm = "System.UInt64" -> ILAttribElem.UInt64 0UL + | Const.Zero when tynm = "System.Single" -> ILAttribElem.Single 0.0f + | Const.Zero when tynm = "System.Double" -> ILAttribElem.Double 0.0 + | Const.Zero when tynm = "System.Char" -> ILAttribElem.Char '\000' | Const.String i when isobj || tynm = "System.String" -> ILAttribElem.String(Some i) | _ -> error (InternalError("The type '" + tynm + "' may not be used as a custom attribute value", m)) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs index 2b51fbf11f7..5c472e0f4b4 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs @@ -303,6 +303,14 @@ module CustomAttributes_Basic = |> verifyCompileAndRun |> shouldSucceed + // SOURCE=OptionalAttributeArgs.fs # OptionalAttributeArgs.fs + // Regression test for https://github.com/dotnet/fsharp/issues/8353 + [] + let ``OptionalAttributeArgs_fs`` compilation = + compilation + |> verifyCompile + |> shouldSucceed + // SOURCE=W_ReturnType03b.fs SCFLAGS="--test:ErrorRanges" # W_ReturnType03b.fs [] let ``W_ReturnType03b_fs`` compilation = diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs new file mode 100644 index 00000000000..630b81a07fc --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs @@ -0,0 +1,48 @@ +// #Regression #Conformance #DeclarationElements #Attributes +// Regression test for https://github.com/dotnet/fsharp/issues/8353 +// Verify that custom attributes with [] parameters (no DefaultParameterValue) compile for all value types + +open System +open System.Runtime.InteropServices + +type BoolAttribute(name : string, flag : bool) = + inherit Attribute() + new([] flag : bool) = BoolAttribute("", flag) + +type IntAttribute(name : string, value : int) = + inherit Attribute() + new([] value : int) = IntAttribute("", value) + +type ByteAttribute(name : string, value : byte) = + inherit Attribute() + new([] value : byte) = ByteAttribute("", value) + +type FloatAttribute(name : string, value : float) = + inherit Attribute() + new([] value : float) = FloatAttribute("", value) + +type SingleAttribute(name : string, value : float32) = + inherit Attribute() + new([] value : float32) = SingleAttribute("", value) + +type CharAttribute(name : string, value : char) = + inherit Attribute() + new([] value : char) = CharAttribute("", value) + +[] +type T1() = class end + +[] +type T2() = class end + +[] +type T3() = class end + +[] +type T4() = class end + +[] +type T5() = class end + +[] +type T6() = class end From e3059a8e0653a7495877e5a58663c50cd18bbca5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 13:28:09 +0000 Subject: [PATCH 3/4] Add comprehensive test coverage for all primitive value types in optional attribute args Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/6f81842d-a307-4b7e-9ef2-ffa78948f9c6 --- .../Basic/OptionalAttributeArgs.fs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs index 630b81a07fc..6ed1c90a519 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs @@ -17,6 +17,30 @@ type ByteAttribute(name : string, value : byte) = inherit Attribute() new([] value : byte) = ByteAttribute("", value) +type SByteAttribute(name : string, value : sbyte) = + inherit Attribute() + new([] value : sbyte) = SByteAttribute("", value) + +type Int16Attribute(name : string, value : int16) = + inherit Attribute() + new([] value : int16) = Int16Attribute("", value) + +type Int64Attribute(name : string, value : int64) = + inherit Attribute() + new([] value : int64) = Int64Attribute("", value) + +type UInt16Attribute(name : string, value : uint16) = + inherit Attribute() + new([] value : uint16) = UInt16Attribute("", value) + +type UInt32Attribute(name : string, value : uint32) = + inherit Attribute() + new([] value : uint32) = UInt32Attribute("", value) + +type UInt64Attribute(name : string, value : uint64) = + inherit Attribute() + new([] value : uint64) = UInt64Attribute("", value) + type FloatAttribute(name : string, value : float) = inherit Attribute() new([] value : float) = FloatAttribute("", value) @@ -46,3 +70,22 @@ type T5() = class end [] type T6() = class end + +[] +type T7() = class end + +[] +type T8() = class end + +[] +type T9() = class end + +[] +type T10() = class end + +[] +type T11() = class end + +[] +type T12() = class end + From a4bbdeb1151f74e3a8ffb8a5f57fa5b10e29378f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 31 Mar 2026 12:33:17 +0200 Subject: [PATCH 4/4] Merge main, add release notes for #8353 fix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index d5c2087765e..45a36522191 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -17,6 +17,7 @@ * Fix `YieldFromFinal`/`ReturnFromFinal` being incorrectly called in non-tail positions (`for`, `use`, `use!`, `try/with` handler). ([Issue #19402](https://github.com/dotnet/fsharp/issues/19402), [PR #19403](https://github.com/dotnet/fsharp/pull/19403)) * Fixed how the source ranges of warn directives are reported (as trivia) in the parser output (by not reporting leading spaces). ([Issue #19405](https://github.com/dotnet/fsharp/issues/19405), [PR #19408]((https://github.com/dotnet/fsharp/pull/19408))) * Fix UoM value type `ToString()` returning garbage values when `--checknulls+` is enabled, caused by double address-taking in codegen. ([Issue #19435](https://github.com/dotnet/fsharp/issues/19435), [PR #19440](https://github.com/dotnet/fsharp/pull/19440)) +* Fix internal error when using custom attribute with `[]` value type parameter and no `[]`. ([Issue #8353](https://github.com/dotnet/fsharp/issues/8353), [PR #19484](https://github.com/dotnet/fsharp/pull/19484)) ### Added