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

Commit4eba761

Browse files
dsymeKevinRansom
authored andcommitted
Fix 3376 (#3520)
1 parentc77f424 commit4eba761

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,16 @@ and [<CompiledName("FSharpExpr")>]
285285
| CombTerm(TryWithOp,[e1;Lambda(v1,e2);Lambda(v2,e3)])-> combL"TryWith"[expr e1; varL v1; expr e2; varL v2; expr e3]
286286
| CombTerm(SequentialOp,args)-> combL"Sequential"(exprs args)
287287
| CombTerm(NewDelegateOp(ty),[e])->
288-
letn=(getDelegateInvoke ty).GetParameters().Length
289-
match ewith
290-
| NLambdas n(vs,e)-> combL"NewDelegate"([typeL ty]@(vs|> List.map varL)@[expr e])
291-
|_-> combL"NewDelegate"[typeL ty; expr e]
288+
letnargs=(getDelegateInvoke ty).GetParameters().Length
289+
if nargs=0then
290+
match ewith
291+
| NLambdas1([_],e)-> combL"NewDelegate"([typeL ty]@[expr e])
292+
| NLambdas0([],e)-> combL"NewDelegate"([typeL ty]@[expr e])
293+
|_-> combL"NewDelegate"[typeL ty; expr e]
294+
else
295+
match ewith
296+
| NLambdas nargs(vs,e)-> combL"NewDelegate"([typeL ty]@(vs|> List.map varL)@[expr e])
297+
|_-> combL"NewDelegate"[typeL ty; expr e]
292298
//| CombTerm(_,args) -> combL "??" (exprs args)
293299
| VarTerm(v)-> wordL(tagLocal v.Name)
294300
| LambdaTerm(v,b)-> combL"Lambda"[varL v; expr b]
@@ -503,10 +509,16 @@ module Patterns =
503509
let(|NewDelegate|_|)e=
504510
match ewith
505511
| Comb1(NewDelegateOp(ty),e)->
506-
letn=(getDelegateInvoke ty).GetParameters().Length
507-
match ewith
508-
| NLambdas n(vs,e)-> Some(ty,vs,e)
509-
|_-> None
512+
letnargs=(getDelegateInvoke ty).GetParameters().Length
513+
if nargs=0then
514+
match ewith
515+
| NLambdas1([_],e)-> Some(ty,[],e)// try to strip the unit parameter if there is one
516+
| NLambdas0([],e)-> Some(ty,[],e)
517+
|_-> None
518+
else
519+
match ewith
520+
| NLambdas nargs(vs,e)-> Some(ty,vs,e)
521+
|_-> None
510522
|_-> None
511523

512524
[<CompiledName("LetRecursivePattern")>]

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,32 @@ module TestStaticCtor =
31063106
testStaticCtor()
31073107

31083108

3109+
moduleTestFuncNoArgs=
3110+
typeSomeType()=classend
3111+
typeTest=
3112+
static memberParseThis(f:System.Linq.Expressions.Expression<System.Func<SomeType>>)= f
3113+
3114+
3115+
typeD=delegateofunit->int
3116+
typeD2<'T>=delegateofunit->'T
3117+
3118+
lettestFunc()=
3119+
check"cvwenklwevpo1"(match<@new System.Func<int>(fun()->3)@>with Quotations.Patterns.NewDelegate(_,[],Value_)->true|_->false)true
3120+
check"cvwenklwevpo2"(match<@new System.Func<int,int>(fun n->3)@>with Quotations.Patterns.NewDelegate(_,[_],Value_)->true|_->false)true
3121+
check"cvwenklwevpo1d"(match<@new D(fun()->3)@>with Quotations.Patterns.NewDelegate(_,[],Value_)->true|_->false)true
3122+
check"cvwenklwevpo2d"(match<@new D2<int>(fun()->3)@>with Quotations.Patterns.NewDelegate(_,[],Value_)->true|_->false)true
3123+
3124+
testFunc()
3125+
3126+
3127+
lettestFunc2()=
3128+
// was raising exception
3129+
letfoo= Test.ParseThis(fun()-> SomeType())
3130+
check"clew0mmlvew"(foo.ToString())"() => new SomeType()"
3131+
3132+
testFunc2()
3133+
3134+
31093135
#if!FX_RESHAPED_REFLECTION
31103136
moduleTestAssemblyAttributes=
31113137
letattributes= System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp