From ccdcf67b3b703a5e18a6a326e5ad7d91e629e196 Mon Sep 17 00:00:00 2001 From: Smaug123 <3138005+Smaug123@users.noreply.github.com> Date: Fri, 21 Mar 2025 14:35:58 +0000 Subject: [PATCH 1/3] Bump NBGV --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 1db18a6..2d09cc6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,7 +13,7 @@ embedded - + From da11d2932cbc23aa70b813f8b6306f3100e48b78 Mon Sep 17 00:00:00 2001 From: Smaug123 <3138005+Smaug123@users.noreply.github.com> Date: Fri, 21 Mar 2025 14:44:26 +0000 Subject: [PATCH 2/3] Work around https://github.com/dotnet/fsharp/issues/18298 --- ShapeSifter.Test/TestUnion.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShapeSifter.Test/TestUnion.fs b/ShapeSifter.Test/TestUnion.fs index 9a9ba99..2b79cb4 100644 --- a/ShapeSifter.Test/TestUnion.fs +++ b/ShapeSifter.Test/TestUnion.fs @@ -11,7 +11,7 @@ open ShapeSifter.Patterns [] module TestUnion = - [] + [] type Foo () = inherit Attribute () From 8a53f7bd238b8864ca66c1b61db94fa8f0502fea Mon Sep 17 00:00:00 2001 From: Smaug123 <3138005+Smaug123@users.noreply.github.com> Date: Fri, 21 Mar 2025 19:37:04 +0000 Subject: [PATCH 3/3] Filter out extra attributes --- ShapeSifter.Test/Attribute.fs | 13 ++++++++++++- ShapeSifter.Test/TestUnion.fs | 13 +++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ShapeSifter.Test/Attribute.fs b/ShapeSifter.Test/Attribute.fs index c777d23..a84cfab 100644 --- a/ShapeSifter.Test/Attribute.fs +++ b/ShapeSifter.Test/Attribute.fs @@ -1,12 +1,13 @@ namespace ShapeSifter.Test +open System.Reflection open ShapeSifter [] module Attribute = /// The F# compiler puts in a bunch of attributes on each of these cases; we're not interested in that. - let filterFromField<'a> (field : TypeField<'a>) = + let filterFromField<'a> (field : TypeField<'a>) : CustomAttributeData list = field.Attributes |> List.filter (fun attr -> [ @@ -16,3 +17,13 @@ module Attribute = ] |> List.forall (fun t -> attr.AttributeType <> t) ) + + /// Remove built-in runtime attributes like CompilerGeneratedAttribute. + let filterRuntime (attrs : CustomAttributeData list) : System.Type list = + attrs + |> List.choose (fun attr -> + if attr.AttributeType.Module.Name = "System.Private.CoreLib.dll" then + None + else + Some attr.AttributeType + ) diff --git a/ShapeSifter.Test/TestUnion.fs b/ShapeSifter.Test/TestUnion.fs index 2b79cb4..bc6eabd 100644 --- a/ShapeSifter.Test/TestUnion.fs +++ b/ShapeSifter.Test/TestUnion.fs @@ -2,6 +2,7 @@ namespace ShapeSifter.Test open System +open System.Reflection open NUnit.Framework open FsUnitTyped @@ -45,20 +46,20 @@ module TestUnion = attributes.Count |> shouldEqual 4 - attributes.["Case1"] |> shouldBeEmpty + attributes.["Case1"] |> Attribute.filterRuntime |> shouldBeEmpty attributes.["Case2"] + |> Attribute.filterRuntime |> List.exactlyOne - |> fun data -> data.AttributeType |> shouldEqual typeof attributes.["Case3"] + |> Attribute.filterRuntime |> List.exactlyOne - |> fun data -> data.AttributeType |> shouldEqual typeof attributes.["Case4"] - |> List.map (fun data -> data.AttributeType) + |> Attribute.filterRuntime |> List.sortBy (fun ty -> ty.Name) |> shouldEqual [ typeof ; typeof ] @@ -86,9 +87,9 @@ module TestUnion = |> Map.ofList attributes.Count |> shouldEqual 2 - attributes.["Field1"] |> shouldBeEmpty + attributes.["Field1"] |> Attribute.filterRuntime |> shouldBeEmpty attributes.["Field2"] + |> Attribute.filterRuntime |> List.exactlyOne - |> fun data -> data.AttributeType |> shouldEqual typeof