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

Commitcbaaae6

Browse files
committed
Better error message when we forgot . in dictionary access
1 parent3d664ba commitcbaaae6

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ let GetRangeOfDiagnostic(err:PhasedDiagnostic) =
203203
| SelfRefObjCtor(_,m)->
204204
Some m
205205

206-
| NotAFunction(_,_,mfun,_)->
206+
| NotAFunction(_,_,_,mfun,_)->
207207
Some mfun
208208

209209
| IllegalFileNameChar(_)-> Some rangeCmdArgs
@@ -453,8 +453,6 @@ let BakedInMemberConstraintNameE() = DeclareResourceString("BakedInMemberConstra
453453
letBadEventTransformationE()= DeclareResourceString("BadEventTransformation","")
454454
letParameterlessStructCtorE()= DeclareResourceString("ParameterlessStructCtor","")
455455
letInterfaceNotRevealedE()= DeclareResourceString("InterfaceNotRevealed","%s")
456-
letNotAFunction1E()= DeclareResourceString("NotAFunction1","")
457-
letNotAFunction2E()= DeclareResourceString("NotAFunction2","")
458456
letTyconBadArgsE()= DeclareResourceString("TyconBadArgs","%s%d%d")
459457
letIndeterminateTypeE()= DeclareResourceString("IndeterminateType","")
460458
letNameClash1E()= DeclareResourceString("NameClash1","%s%s")
@@ -743,11 +741,13 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
743741
os.Append(ParameterlessStructCtorE().Format)|> ignore
744742
| InterfaceNotRevealed(denv,ity,_)->
745743
os.Append(InterfaceNotRevealedE().Format(NicePrint.minimalStringOfType denv ity))|> ignore
746-
| NotAFunction(_,_,_,marg)->
747-
if marg.StartColumn=0then
748-
os.Append(NotAFunction1E().Format)|> ignore
744+
| NotAFunction(_,_,hasIndexer,_,marg)->
745+
if hasIndexerthen
746+
os.Append(FSComp.SR.notAFunctionButMaybeIndexer())|> ignore
747+
elif marg.StartColumn=0then
748+
os.Append(FSComp.SR.notAFunctionButMaybeDeclaration())|> ignore
749749
else
750-
os.Append(NotAFunction2E().Format)|> ignore
750+
os.Append(FSComp.SR.notAFunction())|> ignore
751751

752752
| TyconBadArgs(_,tcref,d,_)->
753753
letexp= tcref.TyparsNoRange.Length

‎src/fsharp/FSComp.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ buildUnexpectedTypeArgs,"The non-generic type '%s' does not expect any type argu
2424
returnUsedInsteadOfReturnBang,"Consider using 'return!' instead of 'return'."
2525
yieldUsedInsteadOfYieldBang,"Consider using 'yield!' instead of 'yield'."
2626
tupleRequiredInAbstractMethod,"\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface."
27+
notAFunction,"This value is not a function and cannot be applied."
28+
notAFunctionButMaybeIndexer,"This value is not a function and cannot be applied. But the given value has an indexer. Did you intend to call obj.[index] instead of obj[index]?"
29+
notAFunctionButMaybeDeclaration,"This value is not a function and cannot be applied. Did you forget to terminate a declaration?"
2730
203,buildInvalidWarningNumber,"Invalid warning number '%s'"
2831
204,buildInvalidVersionString,"Invalid version string '%s'"
2932
205,buildInvalidVersionFile,"Invalid version file '%s'"

‎src/fsharp/FSStrings.resx‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@
180180
<dataname="InterfaceNotRevealed"xml:space="preserve">
181181
<value>The type implements the interface '{0}' but this is not revealed by the signature. You should list the interface in the signature, as the interface will be discoverable via dynamic type casts and/or reflection.</value>
182182
</data>
183-
<dataname="NotAFunction1"xml:space="preserve">
184-
<value>This value is not a function and cannot be applied. Did you forget to terminate a declaration?</value>
185-
</data>
186-
<dataname="NotAFunction2"xml:space="preserve">
187-
<value>This value is not a function and cannot be applied</value>
188-
</data>
189183
<dataname="TyconBadArgs"xml:space="preserve">
190184
<value>The type '{0}' expects {1} type argument(s) but is given {2}</value>
191185
</data>

‎src/fsharp/TcGlobals.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
935935
member valtcref_System_Collections_IEqualityComparer= findSysTyconRef sysCollections"IEqualityComparer"
936936
member valtcref_System_Collections_Generic_IEqualityComparer= findSysTyconRef sysGenerics"IEqualityComparer`1"
937937
member valtcref_System_Collections_Generic_Dictionary= findSysTyconRef sysGenerics"Dictionary`2"
938+
member valtcref_System_Collections_Generic_IDictionary= findSysTyconRef sysGenerics"IDictionary`2"
938939

939940
member valtcref_System_IComparable= findSysTyconRef sys"IComparable"
940941
member valtcref_System_IStructuralComparable= findSysTyconRef sysCollections"IStructuralComparable"

‎src/fsharp/TypeChecker.fs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let mkUnitDelayLambda (g: TcGlobals) m e =
7070

7171
exception BakedInMemberConstraintName of string * range
7272
exception FunctionExpected of DisplayEnv * TType * range
73-
exception NotAFunction of DisplayEnv * TType * range * range
73+
exception NotAFunction of DisplayEnv * TType *bool *range * range
7474
exception Recursion of DisplayEnv * Ident * TType * TType * range
7575
exception RecursiveUseCheckedAtRuntime of DisplayEnv * ValRef * range
7676
exception LetRecEvaluatedOutOfOrder of DisplayEnv * ValRef * ValRef * range
@@ -746,7 +746,7 @@ let UnifyFunctionType extraInfo cenv denv mFunExpr ty =
746746
| Some res -> res
747747
| None ->
748748
match extraInfo with
749-
| Some argm -> error (NotAFunction(denv,ty,mFunExpr,argm))
749+
| Some argm -> error (NotAFunction(denv,ty,false,mFunExpr,argm))
750750
| None -> error (FunctionExpected(denv,ty,mFunExpr))
751751

752752
let ReportImplicitlyIgnoredBoolExpression denv m ty expr =
@@ -8225,7 +8225,14 @@ and Propagate cenv overallTy env tpenv (expr: ApplicableExpr) exprty delayed =
82258225
| _ ->
82268226
// 'delayed' is about to be dropped on the floor, first do rudimentary checking to get name resolutions in its body
82278227
RecordNameAndTypeResolutions_IdeallyWithoutHavingOtherEffects_Delayed cenv env tpenv delayed
8228-
error (NotAFunction(denv,overallTy,mExpr,mArg))
8228+
8229+
match expr.Expr with
8230+
| Expr.Val (d,_,_) when
8231+
HasHeadType cenv.g cenv.g.tcref_System_Collections_Generic_Dictionary d.Type ||
8232+
HasHeadType cenv.g cenv.g.tcref_System_Collections_Generic_IDictionary d.Type
8233+
->
8234+
error (NotAFunction(denv,overallTy,true,mExpr,mArg))
8235+
| _ -> error (NotAFunction(denv,overallTy,false,mExpr,mArg))
82298236

82308237
propagate delayed expr.Range exprty
82318238

@@ -8311,7 +8318,7 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
83118318
let bodyOfCompExpr,tpenv = TcComputationOrSequenceExpression cenv env overallTy mFunExpr (Some(expr.Expr,exprty)) tpenv comp
83128319
TcDelayed cenv overallTy env tpenv mExprAndArg (MakeApplicableExprNoFlex cenv bodyOfCompExpr) (tyOfExpr cenv.g bodyOfCompExpr) ExprAtomicFlag.NonAtomic delayed
83138320
| _ ->
8314-
error (NotAFunction(denv,overallTy,mFunExpr,mArg))
8321+
error (NotAFunction(denv,overallTy,false,mFunExpr,mArg))
83158322

83168323
//-------------------------------------------------------------------------
83178324
// TcLongIdentThen : Typecheck "A.B.C<D>.E.F ... " constructs

‎src/fsharp/TypeChecker.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ val TypeCheckOneSigFile :
6363

6464
exception BakedInMemberConstraintNameofstring*range
6565
exception FunctionExpectedofDisplayEnv*TType*range
66-
exception NotAFunctionofDisplayEnv*TType*range*range
66+
exception NotAFunctionofDisplayEnv*TType*bool*range*range
6767
exception RecursionofDisplayEnv*Ast.Ident*TType*TType*range
6868
exception RecursiveUseCheckedAtRuntimeofDisplayEnv*ValRef*range
6969
exception LetRecEvaluatedOutOfOrderofDisplayEnv*ValRef*ValRef*range

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp