@@ -191,33 +191,44 @@ type C() = class end
191191 |> shouldSucceed
192192
193193 // https://github.com/dotnet/fsharp/issues/12796
194- // Non-empty arrays of user-defined types in custom attributes should produce FS3885 diagnostic .
194+ // Empty arrays of user-defined class types in custom attributes should compile successfully .
195195 // Previously this caused FS0192 internal error in encodeCustomAttrElemType.
196196 [<Fact>]
197- let ``Issue 12796 - Non - empty array of user - defined type in attribute gives proper error `` () =
197+ let ``Issue 12796 - Empty array of class type in attribute compiles , verifies IL , and runs `` () =
198198 FSharp
199199 """
200200module TestModule
201201
202+ open System
202203open System.ComponentModel
204+ open System.Reflection
203205
204206[<AllowNullLiteral>]
205207type A() = class end
206208
207- [<DefaultValue([| (null : A) | ])>]
209+ [<DefaultValue([||] : A[ ])>]
208210type B() = class end
211+
212+ [<EntryPoint>]
213+ let main _ =
214+ let attr = typeof<B>.GetCustomAttribute<DefaultValueAttribute>()
215+ let arr = attr.Value :?> obj[]
216+ if arr.Length <> 0 then failwith "Expected empty array"
217+ printfn "class: len=%d " arr.Length
218+ 0
209219 """
220+ |> asExe
210221 |> compile
211- |> shouldFail
212- |> withErrorCode 3885
213- |> withDiagnosticMessageMatches " not a valid custom attribute argument type"
222+ |> shouldSucceed
223+ |> verifyPEFileWithSystemDlls
224+ |> shouldSucceed
225+ |> run
226+ |> shouldSucceed
227+ |> withStdOutContains " class: len=0"
214228
215229 // https://github.com/dotnet/fsharp/issues/12796
216- // Empty arrays of user-defined types in custom attributes should compile successfully.
217- // The element type is substituted with System.Object since no elements need encoding.
218- // Previously this caused FS0192 internal error in encodeCustomAttrElemType.
219230 [<Fact>]
220- let ``Issue 12796 - Empty array of user - defined type in attribute compiles runs and verifies IL`` () =
231+ let ``Issue 12796 - Empty array of record type in attribute compiles , verifies IL , and runs `` () =
221232 FSharp
222233 """
223234module TestModule
@@ -235,7 +246,8 @@ type B() = class end
235246let main _ =
236247 let attr = typeof<B>.GetCustomAttribute<DefaultValueAttribute>()
237248 let arr = attr.Value :?> obj[]
238- printfn "len=%d " arr.Length
249+ if arr.Length <> 0 then failwith "Expected empty array"
250+ printfn "record: len=%d " arr.Length
239251 0
240252 """
241253 |> asExe
@@ -245,11 +257,11 @@ let main _ =
245257 |> shouldSucceed
246258 |> run
247259 |> shouldSucceed
248- |> withStdOutContains " len=0"
260+ |> withStdOutContains " record: len=0"
249261
250262 // https://github.com/dotnet/fsharp/issues/12796
251263 [<Fact>]
252- let ``Issue 12796 - Empty array of enum type in attribute compiles runs and verifies IL`` () =
264+ let ``Issue 12796 - Empty array of enum type in attribute compiles , verifies IL , and runs `` () =
253265 FSharp
254266 """
255267module TestModule
@@ -267,7 +279,8 @@ type T() = class end
267279let main _ =
268280 let attr = typeof<T>.GetCustomAttribute<DefaultValueAttribute>()
269281 let arr = attr.Value :?> MyEnum[]
270- printfn "len=%d " arr.Length
282+ if arr.Length <> 0 then failwith "Expected empty array"
283+ printfn "enum: len=%d " arr.Length
271284 0
272285 """
273286 |> asExe
@@ -277,11 +290,11 @@ let main _ =
277290 |> shouldSucceed
278291 |> run
279292 |> shouldSucceed
280- |> withStdOutContains " len=0"
293+ |> withStdOutContains " enum: len=0"
281294
282295 // https://github.com/dotnet/fsharp/issues/12796
283296 [<Fact>]
284- let ``Issue 12796 - Empty array of primitive type in attribute compiles runs and verifies IL`` () =
297+ let ``Issue 12796 - Empty array of primitive type in attribute compiles , verifies IL , and runs `` () =
285298 FSharp
286299 """
287300module TestModule
@@ -297,7 +310,8 @@ type T() = class end
297310let main _ =
298311 let attr = typeof<T>.GetCustomAttribute<DefaultValueAttribute>()
299312 let arr = attr.Value :?> int[]
300- printfn "len=%d " arr.Length
313+ if arr.Length <> 0 then failwith "Expected empty array"
314+ printfn "int: len=%d " arr.Length
301315 0
302316 """
303317 |> asExe
@@ -307,4 +321,25 @@ let main _ =
307321 |> shouldSucceed
308322 |> run
309323 |> shouldSucceed
310- |> withStdOutContains " len=0"
324+ |> withStdOutContains " int: len=0"
325+
326+ // https://github.com/dotnet/fsharp/issues/12796
327+ // Non-empty arrays of user-defined types should produce FS3885 diagnostic instead of FS0192 internal error.
328+ [<Fact>]
329+ let ``Issue 12796 - Non - empty array of user - defined type in attribute gives proper error`` () =
330+ FSharp
331+ """
332+ module TestModule
333+
334+ open System.ComponentModel
335+
336+ [<AllowNullLiteral>]
337+ type A() = class end
338+
339+ [<DefaultValue([| (null : A) |])>]
340+ type B() = class end
341+ """
342+ |> compile
343+ |> shouldFail
344+ |> withErrorCode 3885
345+ |> withDiagnosticMessageMatches " not a valid custom attribute argument type"
0 commit comments