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

Commit588de2e

Browse files
factor tcExpr to top level function
add a multiple arguments overloaded method group test
1 parentceb7731 commit588de2e

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/NameOfTests.fs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,20 @@ type MethodGroupTests() =
120120
memberthis.MethodGroup()=()
121121
memberthis.MethodGroup(i:int)=()
122122

123+
memberthis.MethodGroup1(i:int,f:float,s:string)=0
124+
memberthis.MethodGroup1(f:float,l:int64)="foo"
125+
memberthis.MethodGroup1(u:unit->unit->int,h:unit):unit=()
126+
123127
[<Test>]
124-
memberthis.``method group name lookup``()=
128+
memberthis.``single argumentmethod group name lookup``()=
125129
letb= nameof(this.MethodGroup)
126130
Assert.AreEqual("MethodGroup",b)
127131

132+
[<Test>]
133+
memberthis.``multiple argument method group name lookup``()=
134+
letb= nameof(this.MethodGroup1)
135+
Assert.AreEqual("MethodGroup1",b)
136+
128137
[<TestFixture>]
129138
typeFrameworkMethodTests()=
130139
[<Test>]

‎src/fsharp/TypeChecker.fs‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8303,6 +8303,31 @@ and delayRest rest mPrior delayed =
83038303
let mPriorAndLongId = unionRanges mPrior (rangeOfLid longId)
83048304
DelayedDotLookup (rest,mPriorAndLongId) :: delayed
83058305

8306+
//-------------------------------------------------------------------------
8307+
// TcNameOfExpr: Typecheck "nameof" expressions
8308+
//-------------------------------------------------------------------------
8309+
and TcNameOfExpr cenv env tpenv expr =
8310+
match expr with
8311+
| SynExpr.Ident _
8312+
| SynExpr.LongIdent(_, LongIdentWithDots _, _, _) as expr ->
8313+
ignore (TcExprOfUnknownType cenv env tpenv expr)
8314+
| SynExpr.TypeApp (expr, _, types, _, _, _, m) as fullExpr ->
8315+
let idents =
8316+
match expr with
8317+
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _) -> idents
8318+
| SynExpr.Ident ident -> [ident]
8319+
| _ -> []
8320+
match idents with
8321+
| [] -> ()
8322+
| idents ->
8323+
// try to type check it as type application, like A.B.C<D<G>>
8324+
match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInType OpenQualified env.eNameResEnv env.eAccessRights idents (TypeNameResolutionStaticArgsInfo.FromTyArgs types.Length) PermitDirectReferenceToGeneratedType.No with
8325+
| ResultOrException.Result tcref ->
8326+
ignore (TcTypeApp cenv NewTyparsOK NoCheckCxs ItemOccurence.UseInType env tpenv m tcref [] types)
8327+
| _ ->
8328+
// now try to check it as generic function, like func<D<G>>
8329+
ignore (TcExprOfUnknownType cenv env tpenv fullExpr)
8330+
| _ -> ()
83068331

83078332
//-------------------------------------------------------------------------
83088333
// TcFunctionApplicationThen: Typecheck "expr x" + projections
@@ -8328,28 +8353,6 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83288353
| _ -> None
83298354
findIdents expr
83308355

8331-
let tcExpr = function
8332-
| SynExpr.Ident _
8333-
| SynExpr.LongIdent(_, LongIdentWithDots _, _, _) as expr ->
8334-
ignore (TcExprOfUnknownType cenv env tpenv expr)
8335-
| SynExpr.TypeApp (expr, _, types, _, _, _, m) as fullExpr ->
8336-
let idents =
8337-
match expr with
8338-
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _) -> idents
8339-
| SynExpr.Ident ident -> [ident]
8340-
| _ -> []
8341-
match idents with
8342-
| [] -> ()
8343-
| idents ->
8344-
// try to type check it as type application, like A.B.C<D<G>>
8345-
match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInType OpenQualified env.eNameResEnv env.eAccessRights idents (TypeNameResolutionStaticArgsInfo.FromTyArgs types.Length) PermitDirectReferenceToGeneratedType.No with
8346-
| ResultOrException.Result tcref ->
8347-
ignore (TcTypeApp cenv NewTyparsOK NoCheckCxs ItemOccurence.UseInType env tpenv m tcref [] types)
8348-
| _ ->
8349-
// now try to check it as generic function, like func<D<G>>
8350-
ignore (TcExprOfUnknownType cenv env tpenv fullExpr)
8351-
| _ -> ()
8352-
83538356
let rec stripParens expr =
83548357
match expr with
83558358
| SynExpr.Paren(expr, _, _, _) -> stripParens expr
@@ -8364,7 +8367,7 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83648367
let cleanSynArg = stripParens synArg
83658368
match cleanSynArg with
83668369
| LastPartOfLongIdentStripParens lastIdent ->
8367-
tcExpr cleanSynArg
8370+
TcNameOfExpr cenv env tpenv cleanSynArg
83688371
let r = expr.Range
83698372
// generate fake `range` for the constant the `nameof(..)` we are substituting
83708373
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn + lastIdent.idText.Length + 2)) // `2` are for quotes

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp