You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create better error message when implementing an interface with overloads (#1907)
* Create better error message when implementing an interface with overloads - fixes#1905
* Add a test for #1905
* Create better error message when implementing an interface with overloads - fixes#1905
Copy file name to clipboardExpand all lines: src/fsharp/FSComp.txt
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1328,3 +1328,4 @@ tcTupleStructMismatch,"One tuple type is a struct tuple, the other is a referenc
1328
1328
3210,tcNamedActivePattern,"%s is an active pattern and cannot be treated as a discriminated union case with named fields."
1329
1329
3211,DefaultParameterValueNotAppropriateForArgument,"The default value does not have the same type as the argument. The DefaultParameterValue attribute and any Optional attribute will be ignored. Note: 'null' needs to be annotated with the correct type, e.g. 'DefaultParameterValue(null:obj)'."
1330
1330
tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced system DLL contained this type"
1331
+
3213,typrelMemberHasMultiplePossibleDispatchSlots,"The member '%s' matches multiple overloads of the same method.\nPlease restrict it to one of the following:%s."
// Check that no available prior override implements this dispatch slot
288
-
not(DispatchSlotIsAlreadyImplemented g amap m availPriorOverridesKeyed dispatchSlot)then
288
+
not(DispatchSlotIsAlreadyImplemented g amap m availPriorOverridesKeyed dispatchSlot)
289
+
then
289
290
// error reporting path
290
291
let(CompiledSig (vargtys,_vrty,fvmtps,_))= CompiledSigOfMeth g amap m dispatchSlot
291
-
letnoimpl()=if isReqdTyInterface then fail(Error(FSComp.SR.typrelNoImplementationGivenWithSuggestion(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m))
292
-
else fail(Error(FSComp.SR.typrelNoImplementationGiven(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m))
293
-
match overrides |> List.filter (IsPartialMatch g amap m dispatchSlot)with
292
+
letnoimpl()=
293
+
if isReqdTyInterface then
294
+
fail(Error(FSComp.SR.typrelNoImplementationGivenWithSuggestion(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m))
295
+
else
296
+
fail(Error(FSComp.SR.typrelNoImplementationGiven(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m))
297
+
298
+
match overrides |> List.filter (IsPartialMatch g amap m dispatchSlot)with
if argTys.Length <> vargtys.Length then FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfArguments(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot)
302
-
elif mtps.Length <> fvmtps.Length then FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfTypeParameters(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot)
303
-
elifnot(IsTyparKindMatch g amap m dispatchSlot overrideBy)then FSComp.SR.typrelMemberDoesNotHaveCorrectKindsOfGenericParameters(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot)
304
-
else FSComp.SR.typrelMemberCannotImplement(FormatOverride denv overrideBy, NicePrint.stringOfMethInfo amap m denv dispatchSlot, FormatMethInfoSig g amap m denv dispatchSlot)
// Error will be reported below in CheckOverridesAreAllUsedOnce
315
+
()
316
+
317
+
elif argTys.Length <> vargtys.Length then
318
+
fail(Error(FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfArguments(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range))
319
+
elif mtps.Length <> fvmtps.Length then
320
+
fail(Error(FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfTypeParameters(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range))
321
+
elifnot(IsTyparKindMatch g amap m dispatchSlot overrideBy)then
322
+
fail(Error(FSComp.SR.typrelMemberDoesNotHaveCorrectKindsOfGenericParameters(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range))
323
+
else
324
+
fail(Error(FSComp.SR.typrelMemberCannotImplement(FormatOverride denv overrideBy, NicePrint.stringOfMethInfo amap m denv dispatchSlot, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range))
306
325
| overrideBy ::_->
307
326
errorR(Error(FSComp.SR.typrelOverloadNotFound(FormatMethInfoSig g amap m denv dispatchSlot, FormatMethInfoSig g amap m denv dispatchSlot),overrideBy.Range))
Copy file name to clipboardExpand all lines: tests/fsharp/typecheck/sigs/neg10.bsl
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,12 @@ neg10.fs(131,23,131,29): typecheck error FS0906: Type abbreviations cannot have
61
61
62
62
neg10.fs(169,32,169,35): typecheck error FS0035: This construct is deprecated: This form of object expression is not used in F#. Use 'member this.MemberName ... = ...' to define member implementations in object expressions.
63
63
64
-
neg10.fs(169,32,169,33): typecheck error FS0017: The member 'X : unit -> 'a' does not have the correct type to override any given virtual method
64
+
neg10.fs(169,32,169,33): typecheck error FS3213: The member 'X : unit -> 'a' matches multiple overloads of the same method.
65
+
Please restrict it to one of the following:
66
+
67
+
X : unit -> 'a
68
+
69
+
X : unit -> 'a.
65
70
66
71
neg10.fs(169,19,169,26): typecheck error FS0783: At least one override did not correctly implement its corresponding abstract member
Copy file name to clipboardExpand all lines: tests/fsharp/typecheck/sigs/neg26.bsl
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,11 @@ neg26.fs(27,13,27,66): typecheck error FS0366: No implementation was given for '
5
5
6
6
neg26.fs(40,27,40,32): typecheck error FS0361: The override 'Meth1 : int -> int' implements more than one abstract slot, e.g. 'abstract member ITestSub.Meth1 : int -> int' and 'abstract member ITest.Meth1 : int -> int'
7
7
8
-
neg26.fs(53,27,53,32): typecheck error FS0017: The member 'Meth1 : 'a -> 'a' does not have the correct type to override any given virtual method
8
+
neg26.fs(53,27,53,32): typecheck error FS3213: The member 'Meth1 : 'a -> 'a' matches multiple overloads of the same method.
9
+
Please restrict it to one of the following:
10
+
11
+
Meth1 : int -> int
12
+
13
+
Meth1 : int -> int.
9
14
10
15
neg26.fs(52,15,52,23): typecheck error FS0783: At least one override did not correctly implement its corresponding abstract member
0 commit comments