Skip to content

Commit

Permalink
Fix #68 - filter out type initializer from Type.GetConstructor portab…
Browse files Browse the repository at this point in the history
…le implementation
  • Loading branch information
stephen-swensen authored and KevinRansom committed Feb 17, 2015
1 parent b9d2f3f commit c3c50ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ type FSharpQuotationsTests() =
let wrongValue = <@ "!" @>
Check.argumentException(fun () -> ExprShape.RebuildShapeCombination(shape, [wrongValue;lambda]))
| _ -> Assert.Fail()

[<Test>]
member x.GetConstructorFiltersOutStaticConstructor() =
ignore <@ System.Exception() @>
9 changes: 6 additions & 3 deletions src/fsharp/FSharp.Core/reflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3c50ee

Please sign in to comment.