Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0160788
Failing tests
edgarfgp Nov 21, 2023
1115676
static abstract on interfaces
edgarfgp Nov 21, 2023
30e4a33
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Nov 22, 2023
505e346
Use better approach
edgarfgp Nov 22, 2023
b209dd2
Merge branch 'disallow-calling-methods-directly-on-interfaces' of git…
edgarfgp Nov 22, 2023
8206b82
update test that was failing before
edgarfgp Nov 22, 2023
cc2f114
one more test
edgarfgp Nov 23, 2023
75fbdfd
one more test
edgarfgp Nov 23, 2023
818edea
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Nov 23, 2023
487f4c7
Reuse 509 error
edgarfgp Nov 25, 2023
d54679a
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Nov 27, 2023
9a6c4f1
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Nov 28, 2023
37f01d0
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Nov 30, 2023
2934282
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Feb 27, 2024
ed8b771
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Mar 3, 2024
f9124c0
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Mar 4, 2024
ca47da5
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Apr 10, 2024
fc2c61f
Update ResolveOverloading
edgarfgp Apr 10, 2024
3ca92e3
release notes
edgarfgp Apr 10, 2024
fd6ccc1
Merge branch 'main' into disallow-calling-methods-directly-on-interfaces
edgarfgp Apr 10, 2024
e792190
Update check
edgarfgp Apr 10, 2024
328472a
simplify check
edgarfgp Apr 10, 2024
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.300.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fixed

* Disallow calling abstract methods directly on interfaces. ([PR #16319](https://github.com/dotnet/fsharp/pull/16319))
* Fix a false positive of the `[<TailCall>]` analysis in combination with `yield!`. ([PR #16933](https://github.com/dotnet/fsharp/pull/16933))
* Improve error reporting: ambiguous override method in object expression. ([PR #16985](https://github.com/dotnet/fsharp/pull/16985))
* Don't blow the stack when traversing deeply nested sequential expressions. ([PR #16882](https://github.com/dotnet/fsharp/pull/16882))
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9955,9 +9955,9 @@ and TcMethodApplication
let finalCalledMeth =

let callerArgs = { Unnamed = unnamedCurriedCallerArgs ; Named = namedCurriedCallerArgs }

let postArgumentTypeCheckingCalledMethGroup =
preArgumentTypeCheckingCalledMethGroup |> List.map (fun (minfo, minst, pinfoOpt, usesParamArrayConversion) ->
preArgumentTypeCheckingCalledMethGroup
|> List.map (fun (minfo, minst, pinfoOpt, usesParamArrayConversion) ->
let callerTyArgs =
match tyArgsOpt with
| Some tyargs -> minfo.AdjustUserTypeInstForFSharpStyleIndexedExtensionMembers tyargs
Expand Down
13 changes: 11 additions & 2 deletions src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2944,8 +2944,17 @@ and ResolveOverloading
let calledMethOpt, errors, calledMethTrace =

match calledMethGroup, candidates with
| _, [calledMeth] when not isOpConversion ->
Some calledMeth, CompleteD, NoTrace
| _, [calledMeth] when not isOpConversion ->
// See what candidates we have based on name and arity, and check for static/virtual/abstract
// OK: static virtual TResult operator checked i.e. IAdditionOperators.op_CheckedAddition
// Error: static abstract TResult operator i.e. IAdditionOperators.op_Addition
match calledMeth.Method with
| ILMeth(ilMethInfo= ilMethInfo) when ilMethInfo.IsStatic && ilMethInfo.IsVirtual && methodName.Contains("op_") ->
if ilMethInfo.IsAbstract then
None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), NoTrace
else
Some calledMeth, CompleteD, NoTrace
| _ -> Some calledMeth, CompleteD, NoTrace

| [], _ when not isOpConversion ->
None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), NoTrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,4 +1183,33 @@ let execute = IPrintable.Say("hello")
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> withLangVersion80
|> typecheck
|> shouldSucceed
|> shouldSucceed

[<FactForNETCOREAPP>]
let ``Accessing to IWSAM(System.Numerics non virtual) produces a compilation error`` () =
Fsx """
open System.Numerics

IAdditionOperators.op_Addition (3, 6)
"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> withLangVersion80
|> compile
|> shouldFail
|> withSingleDiagnostic (Error 509, Line 4, Col 1, Line 4, Col 38, "Method or object constructor 'op_Addition' not found")

[<FactForNETCOREAPP>]
let ``Accessing to IWSAM(System.Numerics virtual member) compiles and runs`` () =
Fsx """
open System.Numerics

let res = IAdditionOperators.op_CheckedAddition (3, 6)

printf "%A" res"""
|> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ]
|> withLangVersion80
|> asExe
|> compile
|> shouldSucceed
|> run
|> verifyOutput "9"