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

Commit6581790

Browse files
Vasily KirichenkoVasily Kirichenko
Vasily Kirichenko
authored and
Vasily Kirichenko
committed
make it work on simpleIdents
it raises a proper error if applicated to non (Long)Ident arg
1 parent7832be5 commit6581790

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,3 +1335,4 @@ tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced
13351335
3214,methodIsNotStatic,"Method or object constructor '%s' is not static"
13361336
3215,expressionHasNoName,"This expression does not have a name."
13371337
3216,nameofNotPermitted,"The nameof operator is not allowed in this position."
1338+
3217,wrongNameofArgument,"Only identifiers are allowed as argument for nameof operator."

‎src/fsharp/TypeChecker.fs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8252,19 +8252,23 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
82528252
| _ -> expr
82538253

82548254
match stripParens expr with
8255+
| SynExpr.Ident ident -> Some ident
82558256
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _) -> List.tryLast idents
82568257
| _ -> None
82578258

82588259
// If the type of 'synArg' unifies as a function type, then this is a function application, otherwise
82598260
// it is an error or a computation expression
82608261
match UnifyFunctionTypeUndoIfFailed cenv denv mFunExpr exprty with
82618262
| Some (domainTy,resultTy) ->
8262-
match expr, synArg with
8263-
| (ApplicableExpr(_, NameOfExpr cenv.g _, _), LastPartOfLongIdentStripParens argIdent) ->
8264-
let r = expr.Range
8265-
// generate fake `range` for the constant the `nameof(..)` we are substituting
8266-
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn + argIdent.idText.Length + 2)) // `2` are for quotes
8267-
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
8263+
match expr with
8264+
| ApplicableExpr(_, NameOfExpr cenv.g _, _) ->
8265+
match synArg with
8266+
| LastPartOfLongIdentStripParens argIdent ->
8267+
let r = expr.Range
8268+
// generate fake `range` for the constant the `nameof(..)` we are substituting
8269+
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn + argIdent.idText.Length + 2)) // `2` are for quotes
8270+
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
8271+
| _ -> error (Error(FSComp.SR.wrongNameofArgument(), synArg.Range))
82688272
| _ ->
82698273
// Notice the special case 'seq { ... }'. In this case 'seq' is actually a function in the F# library.
82708274
// Set a flag in the syntax tree to say we noticed a leading 'seq'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp