提交 cbaaae63 编写于 作者: S Steffen Forkmann

Better error message when we forgot . in dictionary access

上级 3d664ba0
......@@ -203,7 +203,7 @@ let GetRangeOfDiagnostic(err:PhasedDiagnostic) =
| SelfRefObjCtor(_,m) ->
Some m
| NotAFunction(_,_,mfun,_) ->
| NotAFunction(_,_,_,mfun,_) ->
Some mfun
| IllegalFileNameChar(_) -> Some rangeCmdArgs
......@@ -453,8 +453,6 @@ let BakedInMemberConstraintNameE() = DeclareResourceString("BakedInMemberConstra
let BadEventTransformationE() = DeclareResourceString("BadEventTransformation","")
let ParameterlessStructCtorE() = DeclareResourceString("ParameterlessStructCtor","")
let InterfaceNotRevealedE() = DeclareResourceString("InterfaceNotRevealed","%s")
let NotAFunction1E() = DeclareResourceString("NotAFunction1","")
let NotAFunction2E() = DeclareResourceString("NotAFunction2","")
let TyconBadArgsE() = DeclareResourceString("TyconBadArgs","%s%d%d")
let IndeterminateTypeE() = DeclareResourceString("IndeterminateType","")
let NameClash1E() = DeclareResourceString("NameClash1","%s%s")
......@@ -743,11 +741,13 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
os.Append(ParameterlessStructCtorE().Format) |> ignore
| InterfaceNotRevealed(denv,ity,_) ->
os.Append(InterfaceNotRevealedE().Format (NicePrint.minimalStringOfType denv ity)) |> ignore
| NotAFunction(_,_,_,marg) ->
if marg.StartColumn = 0 then
os.Append(NotAFunction1E().Format) |> ignore
| NotAFunction(_,_,hasIndexer,_,marg) ->
if hasIndexer then
os.Append(FSComp.SR.notAFunctionButMaybeIndexer()) |> ignore
elif marg.StartColumn = 0 then
os.Append(FSComp.SR.notAFunctionButMaybeDeclaration()) |> ignore
else
os.Append(NotAFunction2E().Format) |> ignore
os.Append(FSComp.SR.notAFunction()) |> ignore
| TyconBadArgs(_,tcref,d,_) ->
let exp = tcref.TyparsNoRange.Length
......
......@@ -24,6 +24,9 @@ buildUnexpectedTypeArgs,"The non-generic type '%s' does not expect any type argu
returnUsedInsteadOfReturnBang,"Consider using 'return!' instead of 'return'."
yieldUsedInsteadOfYieldBang,"Consider using 'yield!' instead of 'yield'."
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."
notAFunction,"This value is not a function and cannot be applied."
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]?"
notAFunctionButMaybeDeclaration,"This value is not a function and cannot be applied. Did you forget to terminate a declaration?"
203,buildInvalidWarningNumber,"Invalid warning number '%s'"
204,buildInvalidVersionString,"Invalid version string '%s'"
205,buildInvalidVersionFile,"Invalid version file '%s'"
......
......@@ -180,12 +180,6 @@
<data name="InterfaceNotRevealed" xml:space="preserve">
<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>
</data>
<data name="NotAFunction1" xml:space="preserve">
<value>This value is not a function and cannot be applied. Did you forget to terminate a declaration?</value>
</data>
<data name="NotAFunction2" xml:space="preserve">
<value>This value is not a function and cannot be applied</value>
</data>
<data name="TyconBadArgs" xml:space="preserve">
<value>The type '{0}' expects {1} type argument(s) but is given {2}</value>
</data>
......
......@@ -935,6 +935,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
member val tcref_System_Collections_IEqualityComparer = findSysTyconRef sysCollections "IEqualityComparer"
member val tcref_System_Collections_Generic_IEqualityComparer = findSysTyconRef sysGenerics "IEqualityComparer`1"
member val tcref_System_Collections_Generic_Dictionary = findSysTyconRef sysGenerics "Dictionary`2"
member val tcref_System_Collections_Generic_IDictionary = findSysTyconRef sysGenerics "IDictionary`2"
member val tcref_System_IComparable = findSysTyconRef sys "IComparable"
member val tcref_System_IStructuralComparable = findSysTyconRef sysCollections "IStructuralComparable"
......
......@@ -70,7 +70,7 @@ let mkUnitDelayLambda (g: TcGlobals) m e =
exception BakedInMemberConstraintName of string * range
exception FunctionExpected of DisplayEnv * TType * range
exception NotAFunction of DisplayEnv * TType * range * range
exception NotAFunction of DisplayEnv * TType * bool * range * range
exception Recursion of DisplayEnv * Ident * TType * TType * range
exception RecursiveUseCheckedAtRuntime of DisplayEnv * ValRef * range
exception LetRecEvaluatedOutOfOrder of DisplayEnv * ValRef * ValRef * range
......@@ -746,7 +746,7 @@ let UnifyFunctionType extraInfo cenv denv mFunExpr ty =
| Some res -> res
| None ->
match extraInfo with
| Some argm -> error (NotAFunction(denv,ty,mFunExpr,argm))
| Some argm -> error (NotAFunction(denv,ty,false,mFunExpr,argm))
| None -> error (FunctionExpected(denv,ty,mFunExpr))
let ReportImplicitlyIgnoredBoolExpression denv m ty expr =
......@@ -8225,7 +8225,14 @@ and Propagate cenv overallTy env tpenv (expr: ApplicableExpr) exprty delayed =
| _ ->
// 'delayed' is about to be dropped on the floor, first do rudimentary checking to get name resolutions in its body
RecordNameAndTypeResolutions_IdeallyWithoutHavingOtherEffects_Delayed cenv env tpenv delayed
error (NotAFunction(denv,overallTy,mExpr,mArg))
match expr.Expr with
| Expr.Val (d,_,_) when
HasHeadType cenv.g cenv.g.tcref_System_Collections_Generic_Dictionary d.Type ||
HasHeadType cenv.g cenv.g.tcref_System_Collections_Generic_IDictionary d.Type
->
error (NotAFunction(denv,overallTy,true,mExpr,mArg))
| _ -> error (NotAFunction(denv,overallTy,false,mExpr,mArg))
propagate delayed expr.Range exprty
......@@ -8311,7 +8318,7 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
let bodyOfCompExpr,tpenv = TcComputationOrSequenceExpression cenv env overallTy mFunExpr (Some(expr.Expr,exprty)) tpenv comp
TcDelayed cenv overallTy env tpenv mExprAndArg (MakeApplicableExprNoFlex cenv bodyOfCompExpr) (tyOfExpr cenv.g bodyOfCompExpr) ExprAtomicFlag.NonAtomic delayed
| _ ->
error (NotAFunction(denv,overallTy,mFunExpr,mArg))
error (NotAFunction(denv,overallTy,false,mFunExpr,mArg))
//-------------------------------------------------------------------------
// TcLongIdentThen : Typecheck "A.B.C<D>.E.F ... " constructs
......
......@@ -63,7 +63,7 @@ val TypeCheckOneSigFile :
exception BakedInMemberConstraintName of string * range
exception FunctionExpected of DisplayEnv * TType * range
exception NotAFunction of DisplayEnv * TType * range * range
exception NotAFunction of DisplayEnv * TType * bool * range * range
exception Recursion of DisplayEnv * Ast.Ident * TType * TType * range
exception RecursiveUseCheckedAtRuntime of DisplayEnv * ValRef * range
exception LetRecEvaluatedOutOfOrder of DisplayEnv * ValRef * ValRef * range
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册