Skip to content

Commit

Permalink
Add similar warnings for failwith, invalidArg, nullArg and invalidOp
Browse files Browse the repository at this point in the history
  • Loading branch information
dungpa committed Sep 5, 2015
1 parent a23e312 commit 4794492
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1343,4 +1343,4 @@ estApplyStaticArgumentsForMethodNotImplemented,"A type provider implemented GetS
3186,pickleMissingDefinition,"An error occurred while reading the F# metadata node at position %d in table '%s' of assembly '%s'. The node had no matching declaration. Please report this warning. You may need to recompile the F# assembly you are using."
3187,checkNotSufficientlyGenericBecauseOfScope,"Type inference caused the type variable %s to escape its scope. Consider adding an explicit type parameter declaration or adjusting your code to be less generic."
3188,checkNotSufficientlyGenericBecauseOfScopeAnon,"Type inference caused an inference type variable to escape its scope. Consider adding type annotations to make your code less generic."
3189,checkRaiseArgumentCount,"Function '%s' has at most one argument. Remaining arguments are being ignored."
3189,checkRaiseFamilyFunctionArgumentCount,"Function '%s' applies to at most %d argument(s). Remaining arguments are being ignored."
10 changes: 8 additions & 2 deletions src/fsharp/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,17 @@ and CheckExprInContext (cenv:cenv) (env:env) expr (context:ByrefCallContext) =
if cenv.reportErrors then
let g = cenv.g
match f with
| OptionalCoerce(Expr.Val(v, _, m')) when valRefEq g v g.raise_vref ->
| OptionalCoerce(Expr.Val(v, _, m'))
when (valRefEq g v g.raise_vref || valRefEq g v g.failwith_vref || valRefEq g v g.null_arg_vref || valRefEq g v g.invalid_op_vref) ->
match argsl with
| [] | [_] -> ()
| _ :: _ :: _ ->
warning(Error(FSComp.SR.checkRaiseArgumentCount v.DisplayName, m'))
warning(Error(FSComp.SR.checkRaiseFamilyFunctionArgumentCount(v.DisplayName, 1), m'))
| OptionalCoerce(Expr.Val(v, _, m')) when valRefEq g v g.invalid_arg_vref ->
match argsl with
| [] | [_] | [_; _] -> ()
| _ :: _ :: _ :: _ ->
warning(Error(FSComp.SR.checkRaiseFamilyFunctionArgumentCount(v.DisplayName, 2), m'))
| _ ->
()

Expand Down
22 changes: 22 additions & 0 deletions src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,14 @@ type public TcGlobals =
new_format_info : IntrinsicValRef
raise_info : IntrinsicValRef
raise_vref : ValRef
failwith_info : IntrinsicValRef
failwith_vref : ValRef
invalid_arg_info : IntrinsicValRef
invalid_arg_vref : ValRef
null_arg_info : IntrinsicValRef
null_arg_vref : ValRef
invalid_op_info : IntrinsicValRef
invalid_op_vref : ValRef
lazy_force_info : IntrinsicValRef
lazy_create_info : IntrinsicValRef

Expand Down Expand Up @@ -913,6 +921,11 @@ let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePa
let unchecked_unary_not_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "not" ,None ,Some "Not" ,[], mk_unop_ty bool_ty)

let raise_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "raise" ,None ,Some "Raise" ,[vara],([[mkSysNonGenericTy sys "Exception"]],varaTy))
let failwith_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "failwith" ,None ,Some "FailWith",[vara],([[string_ty]],varaTy))
let invalid_arg_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "invalidArg" ,None ,Some "InvalidArg",[vara],([[string_ty]; [string_ty]],varaTy))
let null_arg_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "nullArg" ,None ,Some "NullArg",[vara],([[string_ty]],varaTy))
let invalid_op_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "invalidOp" ,None ,Some "InvalidOp",[vara],([[string_ty]],varaTy))

let reraise_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "reraise" ,None ,Some "Reraise",[vara], ([[unit_ty]],varaTy))
let typeof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "typeof" ,None ,Some "TypeOf" ,[vara], ([],system_Type_typ))
let methodhandleof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "methodhandleof" ,None ,Some "MethodHandleOf",[vara;varb],([[varaTy --> varbTy]],system_RuntimeMethodHandle_typ))
Expand Down Expand Up @@ -1354,6 +1367,15 @@ let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePa

raise_info = raise_info
raise_vref = ValRefForIntrinsic raise_info
failwith_info = failwith_info
failwith_vref = ValRefForIntrinsic failwith_info
invalid_arg_info = invalid_arg_info
invalid_arg_vref = ValRefForIntrinsic invalid_arg_info
null_arg_info = null_arg_info
null_arg_vref = ValRefForIntrinsic null_arg_info
invalid_op_info = invalid_op_info
invalid_op_vref = ValRefForIntrinsic invalid_op_info

reraise_info = reraise_info
reraise_vref = ValRefForIntrinsic reraise_info
methodhandleof_info = methodhandleof_info
Expand Down

0 comments on commit 4794492

Please sign in to comment.