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

Commitd4647f9

Browse files
dsymeKevinRansom
authored andcommitted
Fix 4790 - exception message on dynamic invocation (dotnet#4806)
* Fix 4790 - exception message on dynamic invocation* fix test* Make test case localizable
1 parentcbb350f commitd4647f9

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

‎src/fsharp/IlxGen.fs‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,14 +3330,19 @@ and CommitCallSequel cenv eenv m cloc cgbuf mustGenerateUnitAfterCall sequel =
33303330
else GenSequel cenv cloc cgbuf sequel
33313331

33323332

3333+
andMakeNotSupportedExnExpr cenv eenv(argExpr,m)=
3334+
letety= mkAppTy(cenv.g.FindSysTyconRef["System"]"NotSupportedException")[]
3335+
letilty= GenType cenv.amap m eenv.tyenv ety
3336+
letmref= mkILCtorMethSpecForTy(ilty,[cenv.g.ilg.typ_String]).MethodRef
3337+
Expr.Op(TOp.ILCall(false,false,false,true,NormalValUse,false,false,mref,[],[],[ety]),[],[argExpr],m)
3338+
33333339
andGenTraitCall cenv cgbuf eenv(traitInfo,argExprs,m)expr sequel=
33343340
letminfoOpt= CommitOperationResult(ConstraintSolver.CodegenWitnessThatTypSupportsTraitConstraint cenv.TcVal cenv.g cenv.amap m traitInfo argExprs)
33353341
match minfoOptwith
33363342
| None->
3337-
letreplacementExpr=
3338-
mkThrow m(tyOfExpr cenv.g expr)
3339-
(mkExnExpr(cenv.g.FindSysTyconRef["System"]"NotSupportedException",
3340-
[ mkString cenv.g m(FSComp.SR.ilDynamicInvocationNotSupported(traitInfo.MemberName))],m))
3343+
letexnArg= mkString cenv.g m(FSComp.SR.ilDynamicInvocationNotSupported(traitInfo.MemberName))
3344+
letexnExpr= MakeNotSupportedExnExpr cenv eenv(exnArg, m)
3345+
letreplacementExpr= mkThrow m(tyOfExpr cenv.g expr) exnExpr
33413346
GenExpr cenv cgbuf eenv SPSuppress replacementExpr sequel
33423347
| Some expr->
33433348
letexpr= cenv.optimizeDuringCodeGen expr
@@ -5162,9 +5167,9 @@ and GenMethodForBinding
51625167
// However still generate the code for reflection etc.
51635168
letbodyExpr=
51645169
if HasFSharpAttribute cenv.g cenv.g.attrib_NoDynamicInvocationAttribute v.Attribsthen
5165-
mkThrow m returnTy
5166-
(mkExnExpr(cenv.g.FindSysTyconRef["System"]"NotSupportedException",
5167-
[ mkString cenv.g m(FSComp.SR.ilDynamicInvocationNotSupported(v.CompiledName))],m))
5170+
letexnArg= mkString cenv.g m(FSComp.SR.ilDynamicInvocationNotSupported(v.CompiledName))
5171+
letexnExpr= MakeNotSupportedExnExprcenv eenv(exnArg, m)
5172+
mkThrow m returnTy exnExpr
51685173
else
51695174
body
51705175

‎tests/fsharp/core/reflect/test2.fs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ module TEst =
300300
let_= printany printany(* =)*)
301301

302302

303+
moduleDynamicCall=
304+
openSystem
305+
openSystem.Reflection
306+
307+
moduleTest=
308+
typeMarker=classend
309+
310+
let inlinecall(a:^a)=
311+
(^a:(memberStuff: Unit-> Unit) a)
312+
313+
314+
letgenericCallMethod= typeof<Test.Marker>.DeclaringType.GetMethod"call"
315+
letcallMethod= genericCallMethod.MakeGenericMethod[| typeof<Object>|]
316+
317+
try
318+
callMethod.Invoke(null,[| Object()|])|> ignore
319+
failwith"expected an exception"
320+
with:? TargetInvocationExceptionas ex->
321+
// The test should cause a NotSupportedException with the Message:
322+
// "Dynamic invocation of %s is not supported"
323+
// %s Will be Stuff Because thats the member that is not supported.
324+
test"wcnr0vj"(ex.InnerException.Message.Contains("Stuff")&& ex.InnerException.GetType()= typeof<System.NotSupportedException>)
303325

304326
#if TESTS_AS_APP
305327
letRUN()=!failures

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp