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

Commit906a934

Browse files
Try to resolve thenameof operator argument to prevent passing anything to it.
1 parentb7763a6 commit906a934

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8308,9 +8308,9 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83088308
| _ -> expr
83098309

83108310
match stripParens expr with
8311-
| SynExpr.Ident ident -> Some ident
8312-
| SynExpr.TypeApp(expr = SynExpr.Ident(ident)) -> Some ident
8313-
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _) -> List.tryLast idents
8311+
| SynExpr.Ident ident -> Some([ident], ident)
8312+
| SynExpr.TypeApp(expr = SynExpr.Ident(ident)) -> Some([ident], ident)
8313+
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _)when not (List.isEmpty idents)->Some (idents,List.last idents)
83148314
| _ -> None
83158315

83168316
// If the type of 'synArg' unifies as a function type, then this is a function application, otherwise
@@ -8320,11 +8320,14 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83208320
match expr with
83218321
| ApplicableExpr(_, NameOfExpr cenv.g _, _) ->
83228322
match synArg with
8323-
| LastPartOfLongIdentStripParens argIdent ->
8323+
| LastPartOfLongIdentStripParens (idents, lastIdent) ->
8324+
// Try to resolve the `nameof` operator argument to prevent passing anything to it.
8325+
ResolveExprLongIdent cenv.tcSink cenv.nameResolver mArg env.eAccessRights env.eNameResEnv TypeNameResolutionInfo.Default idents |> ignore
8326+
83248327
let r = expr.Range
83258328
// generate fake `range` for the constant the `nameof(..)` we are substituting
8326-
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn +argIdent.idText.Length + 2)) // `2` are for quotes
8327-
TcDelayed cenv overallTy env tpenv mExprAndArg (ApplicableExpr(cenv, Expr.Const(Const.String(argIdent.idText), constRange, cenv.g.string_ty), true)) cenv.g.string_ty ExprAtomicFlag.Atomic delayed
8329+
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn +lastIdent.idText.Length + 2)) // `2` are for quotes
8330+
TcDelayed cenv overallTy env tpenv mExprAndArg (ApplicableExpr(cenv, Expr.Const(Const.String(lastIdent.idText), constRange, cenv.g.string_ty), true)) cenv.g.string_ty ExprAtomicFlag.Atomic delayed
83288331
| _ -> error (Error(FSComp.SR.expressionHasNoName(), expr.Range))
83298332
| _ ->
83308333
// Notice the special case 'seq { ... }'. In this case 'seq' is actually a function in the F# library.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp