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 d5c2087765..45a3652219 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 diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 4e3452a2d8..b89df3eb1a 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 2b51fbf11f..5c472e0f4b 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 0000000000..6ed1c90a51 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/OptionalAttributeArgs.fs @@ -0,0 +1,91 @@ +// #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 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) + +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 + +[] +type T7() = class end + +[] +type T8() = class end + +[] +type T9() = class end + +[] +type T10() = class end + +[] +type T11() = class end + +[] +type T12() = class end +