-
Notifications
You must be signed in to change notification settings - Fork 844
error messages: report a list of missing overrides #4983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee4d3f7
6425fc4
1cee02e
404462f
57d0b3f
eec7bee
9d58235
445e82f
9be2e09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,23 +255,30 @@ module DispatchSlotChecking = | |
|
|
||
| let isReqdTyInterface = isInterfaceTy g reqdTy | ||
| let showMissingMethodsAndRaiseErrors = (isReqdTyInterface || not isOverallTyAbstract) | ||
| let res = ref true | ||
| let fail exn = (res := false ; if showMissingMethodsAndRaiseErrors then errorR exn) | ||
|
|
||
| let mutable res = true | ||
| let fail exn = | ||
| res <- false | ||
| if showMissingMethodsAndRaiseErrors then | ||
| errorR exn | ||
|
|
||
| // Index the availPriorOverrides and overrides by name | ||
| let availPriorOverridesKeyed = availPriorOverrides |> NameMultiMap.initBy (fun ov -> ov.LogicalName) | ||
| let overridesKeyed = overrides |> NameMultiMap.initBy (fun ov -> ov.LogicalName) | ||
|
|
||
| dispatchSlots |> List.iter (fun (RequiredSlot(dispatchSlot, isOptional)) -> | ||
|
|
||
| match NameMultiMap.find dispatchSlot.LogicalName overridesKeyed | ||
| |> List.filter (OverrideImplementsDispatchSlot g amap m dispatchSlot) with | ||
| // we accumulate those to compose a more complete error message, see noimpl() bellow. | ||
| let missingOverloadImplementation = ResizeArray() | ||
|
|
||
| for (RequiredSlot(dispatchSlot, isOptional)) in dispatchSlots do | ||
| let maybeResolvedSlot = | ||
| NameMultiMap.find dispatchSlot.LogicalName overridesKeyed | ||
| |> List.filter (OverrideImplementsDispatchSlot g amap m dispatchSlot) | ||
|
|
||
| match maybeResolvedSlot with | ||
| | [ovd] -> | ||
| if not ovd.IsCompilerGenerated then | ||
| let item = Item.MethodGroup(ovd.LogicalName, [dispatchSlot], None) | ||
| CallNameResolutionSink sink (ovd.Range, nenv, item, item, dispatchSlot.FormalMethodTyparInst, ItemOccurence.Implemented, denv, AccessorDomain.AccessibleFromSomewhere) | ||
| sink |> ignore | ||
| () | ||
| let item = Item.MethodGroup(ovd.LogicalName, [dispatchSlot],None) | ||
| CallNameResolutionSink sink (ovd.Range, nenv, item,item, dispatchSlot.FormalMethodTyparInst, ItemOccurence.Implemented, denv,AccessorDomain.AccessibleFromSomewhere) | ||
| | [] -> | ||
| if not isOptional && | ||
| // Check that no available prior override implements this dispatch slot | ||
|
|
@@ -281,10 +288,7 @@ module DispatchSlotChecking = | |
| let compiledSig = CompiledSigOfMeth g amap m dispatchSlot | ||
|
|
||
| let noimpl() = | ||
| if isReqdTyInterface then | ||
| fail(Error(FSComp.SR.typrelNoImplementationGivenWithSuggestion(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m)) | ||
| else | ||
| fail(Error(FSComp.SR.typrelNoImplementationGiven(NicePrint.stringOfMethInfo amap m denv dispatchSlot), m)) | ||
| missingOverloadImplementation.Add((isReqdTyInterface, lazy NicePrint.stringOfMethInfo amap m denv dispatchSlot)) | ||
|
|
||
| match overrides |> List.filter (IsPartialMatch g dispatchSlot compiledSig) with | ||
| | [] -> | ||
|
|
@@ -307,7 +311,7 @@ module DispatchSlotChecking = | |
| if moreThanOnePossibleDispatchSlot then | ||
| noimpl() | ||
|
|
||
| elif argTys.Length <> vargtys.Length then | ||
| elif argTys.Length <> vargtys.Length then | ||
| fail(Error(FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfArguments(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range)) | ||
| elif mtps.Length <> fvmtps.Length then | ||
|
||
| fail(Error(FSComp.SR.typrelMemberDoesNotHaveCorrectNumberOfTypeParameters(FormatOverride denv overrideBy, FormatMethInfoSig g amap m denv dispatchSlot), overrideBy.Range)) | ||
|
|
@@ -324,11 +328,48 @@ module DispatchSlotChecking = | |
| else | ||
| // Error will be reported below in CheckOverridesAreAllUsedOnce | ||
| () | ||
|
|
||
| | _ -> | ||
| fail(Error(FSComp.SR.typrelOverrideWasAmbiguous(FormatMethInfoSig g amap m denv dispatchSlot), m)) | ||
| | _ -> fail(Error(FSComp.SR.typrelMoreThenOneOverride(FormatMethInfoSig g amap m denv dispatchSlot), m))) | ||
| !res | ||
| | _ -> fail(Error(FSComp.SR.typrelMoreThenOneOverride(FormatMethInfoSig g amap m denv dispatchSlot), m)) | ||
|
|
||
| if missingOverloadImplementation.Count > 0 then | ||
| // compose message listing missing override implementation | ||
| let maxDisplayedOverrides = 10 | ||
| let shouldTruncate = missingOverloadImplementation.Count > maxDisplayedOverrides | ||
| let messageWithInterfaceSuggestion = | ||
| // check any of the missing overrides has isReqdTyInterface flag set | ||
| // in which case we use the message "with suggestion" | ||
| missingOverloadImplementation | ||
| |> Seq.map fst | ||
| |> Seq.filter id | ||
| |> Seq.isEmpty | ||
| |> not | ||
|
|
||
| if missingOverloadImplementation.Count = 1 then | ||
| // only one missing override, we have specific message for that | ||
| let signature = (snd missingOverloadImplementation.[0]).Value | ||
| if messageWithInterfaceSuggestion then | ||
| fail(Error(FSComp.SR.typrelNoImplementationGivenWithSuggestion(signature), m)) | ||
| else | ||
| fail(Error(FSComp.SR.typrelNoImplementationGiven(signature), m)) | ||
| else | ||
| let signatures = | ||
| (missingOverloadImplementation | ||
| |> Seq.truncate maxDisplayedOverrides | ||
| |> Seq.map snd | ||
| |> Seq.map (fun signature -> System.Environment.NewLine + "\t'" + signature.Value + "'") | ||
| |> String.concat "") + System.Environment.NewLine | ||
|
|
||
| // we have specific message if the list is truncated | ||
| let messageFunction = | ||
| match shouldTruncate, messageWithInterfaceSuggestion with | ||
| | false, true -> FSComp.SR.typrelNoImplementationGivenSeveralWithSuggestion | ||
| | false, false -> FSComp.SR.typrelNoImplementationGivenSeveral | ||
| | true , true -> FSComp.SR.typrelNoImplementationGivenSeveralTruncatedWithSuggestion | ||
| | true , false -> FSComp.SR.typrelNoImplementationGivenSeveralTruncated | ||
| fail(Error(messageFunction(signatures), m)) | ||
|
|
||
| res | ||
|
|
||
| /// Check all implementations implement some dispatch slot. | ||
| let CheckOverridesAreAllUsedOnce(denv, g, amap, isObjExpr, reqdTy, | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.