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

Commit067955a

Browse files
fix error range in case of wrongnameofoperator argument
1 parenta770e3c commit067955a

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,5 +1333,5 @@ tcTupleStructMismatch,"One tuple type is a struct tuple, the other is a referenc
13331333
tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced system DLL contained this type"
13341334
3213,typrelMemberHasMultiplePossibleDispatchSlots,"The member '%s' matches multiple overloads of the same method.\nPlease restrict it to one of the following:%s."
13351335
3214,methodIsNotStatic,"Method or object constructor '%s' is not static"
1336-
3215,expressionHasNoName,"This expression does not have a name."
1336+
3215,expressionHasNoName,"Expression does not have a name."
13371337
3216,chkNoFirstClassNameOf,"First-class uses of the 'nameof' operator is not permitted."

‎src/fsharp/TypeChecker.fs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8302,27 +8302,27 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83028302
let mFunExpr = expr.Range
83038303

83048304
let (|LastPartOfLongIdentStripParens|_|) expr =
8305-
let rec stripParens expr =
8306-
match expr with
8307-
| SynExpr.Paren(expr, _, _, _) -> stripParens expr
8308-
| _ -> expr
8309-
83108305
let rec findIdents expr =
83118306
match expr with
83128307
| SynExpr.Ident ident -> Some ([ident], ident)
83138308
| SynExpr.TypeApp (expr = expr) -> findIdents expr
83148309
| SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _) when not (List.isEmpty idents) -> Some (idents, List.last idents)
83158310
| _ -> None
8316-
8317-
findIdents (stripParens expr)
8311+
findIdents expr
8312+
8313+
let rec stripParens expr =
8314+
match expr with
8315+
| SynExpr.Paren(expr, _, _, _) -> stripParens expr
8316+
| _ -> expr
83188317

83198318
// If the type of 'synArg' unifies as a function type, then this is a function application, otherwise
83208319
// it is an error or a computation expression
83218320
match UnifyFunctionTypeUndoIfFailed cenv denv mFunExpr exprty with
83228321
| Some (domainTy,resultTy) ->
83238322
match expr with
83248323
| ApplicableExpr(_, NameOfExpr cenv.g _, _) ->
8325-
match synArg with
8324+
let cleanSynArg = stripParens synArg
8325+
match cleanSynArg with
83268326
| LastPartOfLongIdentStripParens (idents, lastIdent) ->
83278327
// Try to resolve the `nameof` operator argument to prevent passing anything to it.
83288328
ResolveExprLongIdent cenv.tcSink cenv.nameResolver mArg env.eAccessRights env.eNameResEnv TypeNameResolutionInfo.Default idents |> ignore
@@ -8331,7 +8331,7 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83318331
// generate fake `range` for the constant the `nameof(..)` we are substituting
83328332
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn + lastIdent.idText.Length + 2)) // `2` are for quotes
83338333
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
8334-
| _ -> error (Error(FSComp.SR.expressionHasNoName(),expr.Range))
8334+
| _ -> error (Error(FSComp.SR.expressionHasNoName(),cleanSynArg.Range))
83358335
| _ ->
83368336
// Notice the special case 'seq { ... }'. In this case 'seq' is actually a function in the F# library.
83378337
// Set a flag in the syntax tree to say we noticed a leading 'seq'

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on const string
3-
//<Expects span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(5,16)" status="error">Expression does not have a name.</Expects>
44

55
letx= nameof(1+2)
66

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(6,16)" status="error">Expression does not have a name.</Expects>
44

55
letf()=1
66
letx= nameof(f())

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on dictionary lookup
3-
//<Expects span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(6,16)" status="error">Expression does not have a name.</Expects>
44

55
letdict=new System.Collections.Generic.Dictionary<int,string>()
66
letb= nameof(dict.[2])

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on const int
3-
//<Expects span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(5,16)" status="error">Expression does not have a name.</Expects>
44

55
letx= nameof1
66

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(6,16)" status="error">Expression does not have a name.</Expects>
44

55
letf x=1* x
66
letx= nameof(f2)

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects span="(7,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(7,16)" status="error">Expression does not have a name.</Expects>
44

55
letf x y= x y
66
letz x=1* x

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on partially applied functions
3-
//<Expects span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(6,16)" status="error">Expression does not have a name.</Expects>
44

55
letf x y= y* x
66
letx= nameof(f2)

‎tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on const string
3-
//<Expects span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects span="(5,16)" status="error">Expression does not have a name.</Expects>
44

55
letx= nameof"string"
66

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp