Skip to content

Commit

Permalink
Better error message when abstract member impl is wrong - fixes #1203
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 31, 2016
1 parent 02b490d commit 6a54b7f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,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'."
769,tcArgumentArityMismatchOneOverload,"The member '%s' does not accept the correct number of arguments. One overload accepts %d arguments. The required signature is '%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
10 changes: 7 additions & 3 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6036,16 +6036,20 @@ 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

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)] ->
let signature = (NicePrint.stringOfMethInfo cenv.amap mBinding env.DisplayEnv absSlot).Replace("abstract ","")
errorR(Error(FSComp.SR.tcArgumentArityMismatch(bindName, List.sum absSlot.NumArgs, signature),mBinding))
| (_,absSlot:MethInfo) :: _ ->
let signature = (NicePrint.stringOfMethInfo cenv.amap mBinding env.DisplayEnv absSlot).Replace("abstract ","")
errorR(Error(FSComp.SR.tcArgumentArityMismatchOneOverload(bindName, List.sum absSlot.NumArgs, signature),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 6a54b7f

Please sign in to comment.