Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit24e0588

Browse files
dsymeKevinRansom
authored andcommitted
fix 1510: Static constructor interferes with ReflectedDefinition (#3224)
* fix 1510: Static constructor interferes with looking up ReflectedDefinition* fix 1510: Static constructor interferes with looking up ReflectedDefinition (2)* fix test
1 parent4ed4eb0 commit24e0588

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

‎src/fsharp/FSharp.Core/quotations.fs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,26 +1107,31 @@ module Patterns =
11071107
lettyp= mkNamedType(tc,tyargs)
11081108
typ.GetField(fldName,staticOrInstanceBindingFlags)|> checkNonNullResult("fldName", SR.GetString1(SR.QfailedToBindField, fldName))// fxcop may not see "fldName" as an arg
11091109

1110+
letbindGenericCctor(tc:Type)=
1111+
tc.GetConstructor(staticBindingFlags,null,[||],null)
1112+
|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))
1113+
11101114
letbindGenericCtor(tc:Type,argTypes:Instantiable<Typelist>)=
11111115
letargtyps= instFormal(getGenericArguments tc) argTypes
11121116
#if FX_PORTABLE_OR_NETSTANDARD
11131117
letargTypes= Array.ofList argtyps
11141118
tc.GetConstructor(argTypes)
11151119
|> bindCtorBySearchIfCandidateIsNull tc argTypes
1116-
|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))// fxcop may not see "tc" as an arg
1120+
|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))
11171121
#else
1118-
tc.GetConstructor(instanceBindingFlags,null,Array.ofList argtyps,null)|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))// fxcop may not see "tc" as an arg
1122+
tc.GetConstructor(instanceBindingFlags,null,Array.ofList argtyps,null)|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))
11191123
#endif
1124+
11201125
letbindCtor(tc,argTypes:Instantiable<Typelist>,tyargs)=
11211126
lettyp= mkNamedType(tc,tyargs)
11221127
letargtyps= argTypes|> inst tyargs
11231128
#if FX_PORTABLE_OR_NETSTANDARD
11241129
letargTypes= Array.ofList argtyps
11251130
typ.GetConstructor(argTypes)
11261131
|> bindCtorBySearchIfCandidateIsNull typ argTypes
1127-
|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))// fxcop may not see "tc" as an arg
1132+
|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))
11281133
#else
1129-
typ.GetConstructor(instanceBindingFlags,null,Array.ofList argtyps,null)|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))// fxcop may not see "tc" as an arg
1134+
typ.GetConstructor(instanceBindingFlags,null,Array.ofList argtyps,null)|> checkNonNullResult("tc", SR.GetString(SR.QfailedToBindConstructor))
11301135
#endif
11311136

11321137
letchop n xs=
@@ -1432,9 +1437,13 @@ module Patterns =
14321437
| Ambiguous(_)-> raise(System.Reflection.AmbiguousMatchException())
14331438
|_-> failwith"unreachable"
14341439
|1->
1435-
letdata= u_MethodInfoData st
1436-
letminfo= bindGenericMeth(data)in
1437-
(minfo:> MethodBase)
1440+
let((tc,_,_,methName,_)as data)= u_MethodInfoData st
1441+
if methName=".cctor"then
1442+
letcinfo= bindGenericCctor tc
1443+
(cinfo:> MethodBase)
1444+
else
1445+
letminfo= bindGenericMeth(data)
1446+
(minfo:> MethodBase)
14381447
|2->
14391448
letdata= u_CtorInfoData st
14401449
letcinfo= bindGenericCtor(data)in

‎src/utils/reshapedreflection.fs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ module internal ReflectionAdapters =
147147
|> Array.filter(fun ei-> ei.Name= name)
148148
|> commit
149149
#endif
150-
memberthis.GetConstructor(_bindingFlags,_binder,argsT:Type[],_parameterModifiers)=
151-
this.GetConstructor(argsT)
150+
memberthis.GetConstructor(bindingFlags,_binder,argsT:Type[],_parameterModifiers)=
151+
this.GetConstructor(bindingFlags,argsT)
152152
memberthis.GetMethod(name,?bindingFlags)=
153153
letbindingFlags= defaultArg bindingFlags publicFlags
154154
this.GetMethods(bindingFlags)
@@ -199,10 +199,11 @@ module internal ReflectionAdapters =
199199
memberthis.IsSealed= this.GetTypeInfo().IsSealed
200200

201201
memberthis.BaseType= this.GetTypeInfo().BaseType
202-
memberthis.GetConstructor(parameterTypes:Type[])=
202+
203+
memberthis.GetConstructor(bindingFlags,parameterTypes:Type[])=
203204
this.GetTypeInfo().DeclaredConstructors
205+
|> Seq.filter(fun ci-> isAcceptable bindingFlags ci.IsStatic ci.IsPublic)
204206
|> Seq.filter(fun ci->
205-
not ci.IsStatic&&//exclude type initializer
206207
(
207208
letparameters= ci.GetParameters()
208209
(parameters.Length= parameterTypes.Length)&&
@@ -211,14 +212,19 @@ module internal ReflectionAdapters =
211212
)
212213
|> Seq.toArray
213214
|> commit
214-
// MSDN: returns an array of Type objects representing all the interfaces implemented or inherited by the current Type.
215-
memberthis.GetInterfaces()= this.GetTypeInfo().ImplementedInterfaces|> Seq.toArray
215+
216+
memberthis.GetConstructor(parameterTypes:Type[])=
217+
this.GetConstructor(BindingFlags.Public||| BindingFlags.NonPublic||| BindingFlags.Instance, parameterTypes)
218+
216219
memberthis.GetConstructors(?bindingFlags)=
217-
letbindingFlags= defaultArg bindingFlagspublicFlags
220+
letbindingFlags= defaultArg bindingFlags(BindingFlags.Public||| BindingFlags.Instance)
218221
// type initializer will also be included in resultset
219222
this.GetTypeInfo().DeclaredConstructors
220223
|> Seq.filter(fun ci-> isAcceptable bindingFlags ci.IsStatic ci.IsPublic)
221224
|> Seq.toArray
225+
226+
// MSDN: returns an array of Type objects representing all the interfaces implemented or inherited by the current Type.
227+
memberthis.GetInterfaces()= this.GetTypeInfo().ImplementedInterfaces|> Seq.toArray
222228
memberthis.GetMethods()= this.GetMethods(publicFlags)
223229
memberthis.Assembly= this.GetTypeInfo().Assembly
224230
memberthis.IsSubclassOf(otherTy:Type)= this.GetTypeInfo().IsSubclassOf(otherTy)

‎tests/fsharp/core/quotes/test.fsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,20 @@ module ReflectionOverTypeInstantiations =
30603060
checkType"test cvweler9" t2true
30613061

30623062

3063+
moduleTestStaticCtor=
3064+
[<ReflectedDefinition>]
3065+
typeT()=
3066+
staticdo printfn"Hello"// removing this makes the RD lookup work
3067+
static memberIdent(x:int)= x
3068+
3069+
lettestStaticCtor()=
3070+
// bug: threw error with message "Could not bind to method"
3071+
check"cvwenklwevpo1"(Expr.TryGetReflectedDefinition(typeof<T>.GetMethod("Ident"))).IsSometrue
3072+
check"cvwenklwevpo2"(Expr.TryGetReflectedDefinition(typeof<T>.GetConstructors(BindingFlags.Static||| BindingFlags.Public||| BindingFlags.NonPublic).[0])).IsSometrue
3073+
3074+
testStaticCtor()
3075+
3076+
30633077
#if!FX_RESHAPED_REFLECTION
30643078
moduleTestAssemblyAttributes=
30653079
letattributes= System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp