Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.400.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fixed

* Error for partial implementation of interface with static and non-static abstract members. ([Issue #17138](https://github.com/dotnet/fsharp/issues/17138), [PR #17160](https://github.com/dotnet/fsharp/pull/17160))
* Optimize simple mappings with preludes in computed collections. ([PR #17067](https://github.com/dotnet/fsharp/pull/17067))
* Improve error reporting for abstract members when used in classes. ([PR #17063](https://github.com/dotnet/fsharp/pull/17063))
* Improve error reporting when property has same name as DU case. ([Issue #16646](https://github.com/dotnet/fsharp/issues/16646), [PR #17088](https://github.com/dotnet/fsharp/pull/17088))
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7189,7 +7189,9 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI

DispatchSlotChecking.CheckOverridesAreAllUsedOnce (env.DisplayEnv, g, cenv.infoReader, true, implTy, dispatchSlotsKeyed, availPriorOverrides, overrideSpecs)

DispatchSlotChecking.CheckDispatchSlotsAreImplemented (env.DisplayEnv, cenv.infoReader, m, env.NameEnv, cenv.tcSink, false, true, implTy, dispatchSlots, availPriorOverrides, overrideSpecs) |> ignore)
if not hasStaticMembers then
DispatchSlotChecking.CheckDispatchSlotsAreImplemented (env.DisplayEnv, cenv.infoReader, m, env.NameEnv, cenv.tcSink, false, implTy, dispatchSlots, availPriorOverrides, overrideSpecs) |> ignore
)

// 3. create the specs of overrides
let allTypeImpls =
Expand Down
12 changes: 4 additions & 8 deletions src/Compiler/Checking/MethodOverrides.fs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ module DispatchSlotChecking =
let CheckDispatchSlotsAreImplemented (denv, infoReader: InfoReader, m,
nenv, sink: TcResultsSink,
isOverallTyAbstract,
isObjExpr: bool,
reqdTy,
dispatchSlots: RequiredSlot list,
availPriorOverrides: OverrideInfo list,
Expand Down Expand Up @@ -380,8 +379,7 @@ module DispatchSlotChecking =
let compiledSig = CompiledSigOfMeth g amap m dispatchSlot

let noimpl() =
if dispatchSlot.IsInstance then
missingOverloadImplementation.Add((isReqdTyInterface, lazy NicePrint.stringOfMethInfo infoReader m denv dispatchSlot))
missingOverloadImplementation.Add((isReqdTyInterface, lazy NicePrint.stringOfMethInfo infoReader m denv dispatchSlot))

match overrides |> List.filter (IsPartialMatch g dispatchSlot compiledSig) with
| [] ->
Expand All @@ -404,10 +402,8 @@ module DispatchSlotChecking =

let (CompiledSig (vargTys, _, fvmethTypars, _)) = compiledSig

// Object expressions can only implement instance members
let isObjExprWithInstanceMembers = (isObjExpr && isInstance)
if isObjExprWithInstanceMembers || isInstance then
if moreThanOnePossibleDispatchSlot then
if isInstance then
if moreThanOnePossibleDispatchSlot then
noimpl()

elif (argTys.Length <> vargTys.Length) then
Expand Down Expand Up @@ -828,7 +824,7 @@ module DispatchSlotChecking =

if isImplementation && not (isInterfaceTy g overallTy) then
let overrides = allImmediateMembersThatMightImplementDispatchSlots |> List.map snd
let allCorrect = CheckDispatchSlotsAreImplemented (denv, infoReader, m, nenv, sink, tcaug.tcaug_abstract, false, reqdTy, dispatchSlots, availPriorOverrides, overrides)
let allCorrect = CheckDispatchSlotsAreImplemented (denv, infoReader, m, nenv, sink, tcaug.tcaug_abstract, reqdTy, dispatchSlots, availPriorOverrides, overrides)

// Tell the user to mark the thing abstract if it was missing implementations
if not allCorrect && not tcaug.tcaug_abstract && (isClassTy g reqdTy) then
Expand Down
1 change: 0 additions & 1 deletion src/Compiler/Checking/MethodOverrides.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ module DispatchSlotChecking =
nenv: NameResolutionEnv *
sink: TcResultsSink *
isOverallTyAbstract: bool *
isObjExpr: bool *
reqdTy: TType *
dispatchSlots: RequiredSlot list *
availPriorOverrides: OverrideInfo list *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,3 +1269,133 @@ type A () =
|> withDiagnostics [
(Error 3867, Line 3, Col 21, Line 3, Col 22, "Classes cannot contain static abstract members.")
]

[<FactForNETCOREAPP>]
let ``Error for partial implementation of interface with static abstract members`` () =
Fsx """
type IFace =
static abstract P1 : int
static abstract P2 : int

type T =
interface IFace with
static member P1 = 1

"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 7, Col 15, Line 7, Col 20, "No implementation was given for 'static abstract IFace.P2: int'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]

[<FactForNETCOREAPP>]
let ``Error for no implementation of interface with static abstract members`` () =
Fsx """
type IFace =
static abstract P1 : int
static abstract P2 : int

type T =
interface IFace with
"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 7, Col 15, Line 7, Col 20, "No implementation was given for those members:
'static abstract IFace.P1: int'
'static abstract IFace.P2: int'
Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]

[<FactForNETCOREAPP>]
let ``Error for partial implementation of interface with static and non static abstract members`` () =
Fsx """
type IFace =
static abstract P1 : int
static abstract P2 : int
abstract member P3 : int
abstract member P4 : int

type T =
interface IFace with
static member P1 = 1
member this.P3 = 3

"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 9, Col 15, Line 9, Col 20, "No implementation was given for those members:
'static abstract IFace.P2: int'
'abstract IFace.P4: int'
Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]

[<FactForNETCOREAPP>]
let ``Error for no implementation of interface with static and non static abstract members`` () =
Fsx """
type IFace =
static abstract P1 : int
static abstract P2 : int
abstract member P3 : int
abstract member P4 : int

type T =
interface IFace with

"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 9, Col 15, Line 9, Col 20, "No implementation was given for those members:
'static abstract IFace.P1: int'
'static abstract IFace.P2: int'
'abstract IFace.P3: int'
'abstract IFace.P4: int'
Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]

[<FactForNETCOREAPP>]
let ``Error for partial implementation of interface with non static abstract members`` () =
Fsx """
type IFace =
abstract member P3 : int
abstract member P4 : int

type T =
interface IFace with
member this.P3 = 3

"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 7, Col 15, Line 7, Col 20, "No implementation was given for 'abstract IFace.P4: int'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]

[<FactForNETCOREAPP>]
let ``Error for no implementation of interface with non static abstract members`` () =
Fsx """
type IFace =
abstract member P3 : int
abstract member P4 : int

type T =
interface IFace with

"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 7, Col 15, Line 7, Col 20, "No implementation was given for those members:
'abstract IFace.P3: int'
'abstract IFace.P4: int'
Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
]