From c3c50eef8962ac9a9c543d5f21701c4292ee7830 Mon Sep 17 00:00:00 2001 From: Stephen Swensen Date: Mon, 16 Feb 2015 00:37:08 -0500 Subject: [PATCH] Fix #68 - filter out type initializer from Type.GetConstructor portable implementation --- .../Microsoft.FSharp.Quotations/FSharpQuotations.fs | 4 ++++ src/fsharp/FSharp.Core/reflect.fs | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Quotations/FSharpQuotations.fs b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Quotations/FSharpQuotations.fs index 74427ea5079..8569f187d1e 100644 --- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Quotations/FSharpQuotations.fs +++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Quotations/FSharpQuotations.fs @@ -67,3 +67,7 @@ type FSharpQuotationsTests() = let wrongValue = <@ "!" @> Check.argumentException(fun () -> ExprShape.RebuildShapeCombination(shape, [wrongValue;lambda])) | _ -> Assert.Fail() + + [] + member x.GetConstructorFiltersOutStaticConstructor() = + ignore <@ System.Exception() @> \ No newline at end of file diff --git a/src/fsharp/FSharp.Core/reflect.fs b/src/fsharp/FSharp.Core/reflect.fs index bb0a76051df..57034bd6802 100644 --- a/src/fsharp/FSharp.Core/reflect.fs +++ b/src/fsharp/FSharp.Core/reflect.fs @@ -125,9 +125,12 @@ module ReflectionAdapters = member this.GetConstructor(parameterTypes : Type[]) = this.GetTypeInfo().DeclaredConstructors |> Seq.filter (fun ci -> - let parameters = ci.GetParameters() - (parameters.Length = parameterTypes.Length) && - (parameterTypes, parameters) ||> Array.forall2 (fun ty pi -> pi.ParameterType.Equals ty) + not ci.IsStatic && //exclude type initializer + ( + let parameters = ci.GetParameters() + (parameters.Length = parameterTypes.Length) && + (parameterTypes, parameters) ||> Array.forall2 (fun ty pi -> pi.ParameterType.Equals ty) + ) ) |> Seq.toArray |> commit