Skip to content

Commit

Permalink
Fix dotnet#68 - filter out type initializer from Type.GetConstructor …
Browse files Browse the repository at this point in the history
…portable implementation
  • Loading branch information
stephen-swensen committed Feb 16, 2015
1 parent 35e6a00 commit df0c8c9
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 df0c8c9

Please sign in to comment.