Skip to content

Commit

Permalink
Better error message when abstract member impl is wrong - fixes dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 31, 2016
1 parent 02b490d commit 3f73fdf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ commaInsteadOfSemicolonInRecord,"A ';' is used to separate field values in recor
buildUnexpectedTypeArgs,"The non-generic type '%s' does not expect any type arguments, but here is given %d type argument(s)"
returnUsedInsteadOfReturnBang,"Consider using 'return!' instead of 'return'."
yieldUsedInsteadOfYieldBang,"Consider using 'yield!' instead of 'yield'."
tupleRequired,"\nA tuple type was required in one of the parameters. Consider to put the given arguments in additional parentheses."
203,buildInvalidWarningNumber,"Invalid warning number '%s'"
204,buildInvalidVersionString,"Invalid version string '%s'"
205,buildInvalidVersionFile,"Invalid version file '%s'"
Expand Down Expand Up @@ -588,8 +589,8 @@ tcExpressionWithIfRequiresParenthesis,"This list or array expression includes an
765,tcExtraneousFieldsGivenValues,"Extraneous fields have been given values"
766,tcObjectExpressionsCanOnlyOverrideAbstractOrVirtual,"Only overrides of abstract and virtual members may be specified in object expressions"
767,tcNoAbstractOrVirtualMemberFound,"The member '%s' does not correspond to any abstract or virtual method available to override or implement"
768,tcArgumentArityMismatch,"The member '%s' does not accept the correct number of arguments, %d arguments are expected"
769,tcArgumentArityMismatchOneOverload,"The member '%s' does not accept the correct number of arguments. One overload accepts %d arguments."
768,tcArgumentArityMismatch,"The member '%s' does not accept the correct number of arguments. %d argument(s) are expected. The required signature is '%s'.%s"
769,tcArgumentArityMismatchOneOverload,"The member '%s' does not accept the correct number of arguments. One overload accepts %d arguments. The required signature is '%s'.%s"
770,tcSimpleMethodNameRequired,"A simple method name is required here"
771,tcPredefinedTypeCannotBeUsedAsSuperType,"The types System.ValueType, System.Enum, System.Delegate, System.MulticastDelegate and System.Array cannot be used as super types in an object expression or class"
772,tcNewMustBeUsedWithNamedType,"'new' must be used with a named type"
Expand Down
15 changes: 11 additions & 4 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6036,16 +6036,23 @@ and GetNameAndArityOfObjExprBinding _cenv _env b =
lookPat pat


and FreshenObjExprAbstractSlot cenv (_env: TcEnv) implty virtNameAndArityPairs (bind,bindAttribs,bindName,absSlots:(_ * MethInfo) list) =
and FreshenObjExprAbstractSlot cenv (env: TcEnv) implty virtNameAndArityPairs (bind,bindAttribs,bindName,absSlots:(_ * MethInfo) list) =
let (NormalizedBinding (_,_,_,_,_,_,synTyparDecls,_,_,_,mBinding,_)) = bind
match absSlots with
| [] when not (CompileAsEvent cenv.g bindAttribs) ->
let absSlotsByName = List.filter (fst >> fst >> (=) bindName) virtNameAndArityPairs

let getSignature absSlot = (NicePrint.stringOfMethInfo cenv.amap mBinding env.DisplayEnv absSlot).Replace("abstract ","")
let getDetails (absSlot:MethInfo) =
if absSlot.GetParamTypes(cenv.amap,mBinding,[]) |> List.exists (fun xs -> xs |> List.exists (isTupleTy cenv.g)) then
FSComp.SR.tupleRequired()
else ""

match absSlotsByName with
| [] -> errorR(Error(FSComp.SR.tcNoAbstractOrVirtualMemberFound(bindName),mBinding))
| [(_,absSlot:MethInfo)] -> errorR(Error(FSComp.SR.tcArgumentArityMismatch(bindName, (List.sum absSlot.NumArgs)),mBinding))
| (_,absSlot:MethInfo) :: _ -> errorR(Error(FSComp.SR.tcArgumentArityMismatchOneOverload(bindName, (List.sum absSlot.NumArgs)),mBinding))
| [(_,absSlot:MethInfo)] ->
errorR(Error(FSComp.SR.tcArgumentArityMismatch(bindName, List.sum absSlot.NumArgs, getSignature absSlot, getDetails absSlot),mBinding))
| (_,absSlot:MethInfo) :: _ ->
errorR(Error(FSComp.SR.tcArgumentArityMismatchOneOverload(bindName, List.sum absSlot.NumArgs, getSignature absSlot, getDetails absSlot),mBinding))

None

Expand Down
12 changes: 12 additions & 0 deletions tests/fsharpqa/Source/Warnings/TupleInAbstractMethod.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// #Warnings
//<Expects status="Error" span="(9,16)" id="FS0768">The member 'Function' does not accept the correct number of arguments. 1 argument(s) are expected. The required signature is 'member IInterface.Function : (int32 * int32) -> unit'.</Expects>

type IInterface =
abstract Function : (int32 * int32) -> unit

let x =
{ new IInterface with
member this.Function (i, j) = ()
}

exit 0
1 change: 1 addition & 0 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SOURCE=WarnIfMissingElseBranch.fs # WarnIfMissingElseBranch.fs
SOURCE=ReturnInsteadOfReturnBang.fs # ReturnInsteadOfReturnBang.fs
SOURCE=YieldInsteadOfYieldBang.fs # YieldInsteadOfYieldBang.fs
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs
SOURCE=CommaInRecCtor.fs # CommaInRecCtor.fs
SOURCE=ValidCommaInRecCtor.fs # ValidCommaInRecCtor.fs
SOURCE=ElseBranchHasWrongType.fs # ElseBranchHasWrongType.fs
Expand Down

0 comments on commit 3f73fdf

Please sign in to comment.