From 01607886a66188b47a6c02666526d665aba785a7 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 21 Nov 2023 16:35:37 +0000 Subject: [PATCH 01/11] Failing tests --- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 7a5b9991113..ba28c8ed37c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -1184,4 +1184,43 @@ let execute = IPrintable.Say("hello") |> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ] |> withLangVersion80 |> typecheck - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + + [] + let ``Accessing to IWSAM static abstract member produces a compilation error`` () = + Fsx """ +type IPrintable = + static abstract member Log: string -> string + +type SomeClass1() = + member this.GetLog(s: string) = IPrintable.Log(s) + + static member Log(s: string) = s + + interface IPrintable with + static member Log(s: string) = s + +let x = IPrintable.Log("hello") + """ + |> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ] + |> withLangVersion80 + |> compile + |> shouldFail + |> withDiagnostics [ + + ] + + [] + let ``Accessing to IWSAM(System.Numerics) static abstract member produces a compilation error`` () = + Fsx """ +open System.Numerics + +IAdditionOperators.op_Addition (3, 6) + """ + |> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ] + |> withLangVersion80 + |> compile + |> shouldFail + |> withDiagnostics [ + + ] \ No newline at end of file From 1115676cfd65b61ba62cda130c3b64770d57f21a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 21 Nov 2023 21:09:15 +0000 Subject: [PATCH 02/11] static abstract on interfaces --- src/Compiler/Checking/CheckExpressions.fs | 3 +++ src/Compiler/FSComp.txt | 3 ++- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ .../TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 5 +++-- 16 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index b268e80bf0b..951560455c3 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9800,6 +9800,9 @@ and TcMethodApplication | accessibleMeths -> accessibleMeths let candidates = candidateMethsAndProps |> List.map fst + for candidate in candidates do + if isInterfaceTyconRef candidate.DeclaringTyconRef && candidate.IsAbstract && not candidate.IsInstance then + errorR(Error(FSComp.SR.chkStaticMembersDirectlyOnInterfaces(), mItem)) // Step 0. Split the syntactic arguments (if any) into named and unnamed parameters let curriedCallerArgsOpt, unnamedDelayedCallerArgExprOpt, exprTy = diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 371d9c1b45d..8a32b5355ad 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1730,4 +1730,5 @@ featureUnmanagedConstraintCsharpInterop,"Interop between C#'s and F#'s unmanaged 3584,tcDotLambdaAtNotSupportedExpression,"Shorthand lambda syntax is only supported for atomic expressions, such as method, property, field or indexer on the implied '_' argument. For example: 'let f = _.Length'." 3855,tcNoStaticMemberFoundForOverride,"No static abstract member was found that corresponds to this override" 3859,tcNoStaticPropertyFoundForOverride,"No static abstract property was found that corresponds to this override" -3860,chkStaticMembersOnObjectExpressions,"Object expressions cannot implement interfaces with static abstract members or declare static members." \ No newline at end of file +3860,chkStaticMembersOnObjectExpressions,"Object expressions cannot implement interfaces with static abstract members or declare static members." +3861,chkStaticMembersDirectlyOnInterfaces,"Interfaces cannot access static abstract members directly." \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index c0d088ea3f9..bd732b6c1c9 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -122,6 +122,11 @@ Člen nebo funkce „{0}“ má atribut „TailCallAttribute“, ale nepoužívá se koncovým (tail) rekurzivním způsobem. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 3803d2bf627..660100fd841 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -122,6 +122,11 @@ Der Member oder die Funktion "{0}" weist das Attribut "TailCallAttribute" auf, wird jedoch nicht endrekursiv verwendet. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index fa96a65979a..ecb35b94da5 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -122,6 +122,11 @@ El miembro o la función “{0}” tiene el atributo “TailCallAttribute”, pero no se usa de forma de recursión de cola. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index e21b188aa68..df5d669f87a 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -122,6 +122,11 @@ Le membre ou la fonction « {0} » possède l'attribut « TailCallAttribute », mais n'est pas utilisé de manière récursive. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 72a5376bedb..f03979d4073 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -122,6 +122,11 @@ Il membro o la funzione "{0}" ha l'attributo "TailCallAttribute", ma non è in uso in modo ricorsivo finale. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 7aadd7ccd3a..185616d31a6 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -122,6 +122,11 @@ メンバーまたは関数 '{0}' には 'TailCallAttribute' 属性がありますが、末尾の再帰的な方法では使用されていません。 + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index a9a6edf8c68..ce774f68904 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -122,6 +122,11 @@ 멤버 또는 함수 '{0}'에 'TailCallAttribute' 특성이 있지만 비상 재귀적인 방식으로 사용되고 있지 않습니다. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index fcc032441fe..e7a8cd7cd46 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -122,6 +122,11 @@ Składowa lub funkcja „{0}” ma atrybut „TailCallAttribute”, ale nie jest używana w sposób cykliczny końca. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index d56df03beb9..783d3c762a7 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -122,6 +122,11 @@ O membro ou a função "{0}" tem o atributo "TailCallAttribute", mas não está sendo usado de maneira recursiva em cauda. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 7a1e4262565..af37b0f792f 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -122,6 +122,11 @@ Элемент или функция "{0}" содержит атрибут "TailCallAttribute", но не используется в рекурсивном хвостовом режиме. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 724de8db79c..6ac92585e3d 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -122,6 +122,11 @@ Üye veya '{0}' işlevi, 'TailCallAttribute' özniteliğine sahip ancak kuyruk özyinelemeli bir şekilde kullanılmıyor. + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index a10b2125d6e..377a53f9cb6 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -122,6 +122,11 @@ 成员或函数“{0}”具有 "TailCallAttribute" 属性,但未以尾递归方式使用。 + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index ad37f7fdc29..3724fd80f7c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -122,6 +122,11 @@ 成員或函式 '{0}' 具有 'TailCallAttribute' 屬性,但未以尾遞迴方式使用。 + + Interfaces cannot access static abstract members directly. + Interfaces cannot access static abstract members directly. + + Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index ba28c8ed37c..07d6bbff19c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -1207,7 +1207,8 @@ let x = IPrintable.Log("hello") |> compile |> shouldFail |> withDiagnostics [ - + (Error 3861, Line 6, Col 37, Line 6, Col 51, "Interfaces cannot access static abstract members directly."); + (Error 3861, Line 13, Col 9, Line 13, Col 23, "Interfaces cannot access static abstract members directly.") ] [] @@ -1222,5 +1223,5 @@ IAdditionOperators.op_Addition (3, 6) |> compile |> shouldFail |> withDiagnostics [ - + (Error 3861, Line 4, Col 1, Line 4, Col 31, "Interfaces cannot access static abstract members directly.") ] \ No newline at end of file From 505e346cf6370626be1b38d0a3c9cd956a88310a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 22 Nov 2023 20:20:44 +0000 Subject: [PATCH 03/11] Use better approach --- src/Compiler/Checking/CheckExpressions.fs | 14 +++++++++----- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 6 +----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 951560455c3..e7ce9cc1e76 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9800,10 +9800,6 @@ and TcMethodApplication | accessibleMeths -> accessibleMeths let candidates = candidateMethsAndProps |> List.map fst - for candidate in candidates do - if isInterfaceTyconRef candidate.DeclaringTyconRef && candidate.IsAbstract && not candidate.IsInstance then - errorR(Error(FSComp.SR.chkStaticMembersDirectlyOnInterfaces(), mItem)) - // Step 0. Split the syntactic arguments (if any) into named and unnamed parameters let curriedCallerArgsOpt, unnamedDelayedCallerArgExprOpt, exprTy = TcMethodApplication_SplitSynArguments cenv env tpenv isProp candidates exprTy curriedCallerArgs mItem @@ -9840,8 +9836,16 @@ and TcMethodApplication let callerArgs = { Unnamed = unnamedCurriedCallerArgs ; Named = namedCurriedCallerArgs } + for minfo, _, _, _ in preArgumentTypeCheckingCalledMethGroup do + match minfo with + | ILMeth(ilMethInfo = ilMethInfo) -> + if ilMethInfo.IsStatic && ilMethInfo.IsAbstract then + errorR(Error(FSComp.SR.chkStaticMembersDirectlyOnInterfaces(), mItem)) + | _ -> () + 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 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 07d6bbff19c..7174569323e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -1205,11 +1205,7 @@ let x = IPrintable.Log("hello") |> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ] |> withLangVersion80 |> compile - |> shouldFail - |> withDiagnostics [ - (Error 3861, Line 6, Col 37, Line 6, Col 51, "Interfaces cannot access static abstract members directly."); - (Error 3861, Line 13, Col 9, Line 13, Col 23, "Interfaces cannot access static abstract members directly.") - ] + |> shouldSucceed // TODO: shouldFail [] let ``Accessing to IWSAM(System.Numerics) static abstract member produces a compilation error`` () = From 8206b82e3733532f3d9374818c12e9b366dd4d58 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 22 Nov 2023 20:34:05 +0000 Subject: [PATCH 04/11] update test that was failing before --- .../TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 7174569323e..8d8857286e9 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -920,7 +920,10 @@ let main _ = |> withNoWarn 3535 |> withLangVersion70 |> compile - |> shouldSucceed + |> shouldFail + |> withDiagnostics [ + (Error 3861, Line 13, Col 71, Line 13, Col 79, "Interfaces cannot access static abstract members directly.") + ] [] let ``Produce an error when one leaves out keyword "static" in an implementation of IWSAM`` () = From cc2f1148f9306fc8f05c87a67f27b73157447ab9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 23 Nov 2023 08:56:57 +0000 Subject: [PATCH 05/11] one more test --- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 8d8857286e9..a82db7ff324 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -1211,7 +1211,7 @@ let x = IPrintable.Log("hello") |> shouldSucceed // TODO: shouldFail [] - let ``Accessing to IWSAM(System.Numerics) static abstract member produces a compilation error`` () = + let ``Accessing to IWSAM(System.Numerics non virtual) produces a compilation error`` () = Fsx """ open System.Numerics @@ -1221,6 +1221,20 @@ IAdditionOperators.op_Addition (3, 6) |> withLangVersion80 |> compile |> shouldFail - |> withDiagnostics [ - (Error 3861, Line 4, Col 1, Line 4, Col 31, "Interfaces cannot access static abstract members directly.") - ] \ No newline at end of file + |> withSingleDiagnostic (Error 3861, Line 4, Col 1, Line 4, Col 31, "Interfaces cannot access static abstract members directly.") + + [] + 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" \ No newline at end of file From 75fbdfd2c1e3be85a6101aedbebefeb0ab9e7bf4 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 23 Nov 2023 10:39:49 +0000 Subject: [PATCH 06/11] one more test --- src/Compiler/Checking/CheckExpressions.fs | 4 ++-- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 21 ------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 44a43bc53e1..fd8c32cad27 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9809,6 +9809,7 @@ and TcMethodApplication | accessibleMeths -> accessibleMeths let candidates = candidateMethsAndProps |> List.map fst + // Step 0. Split the syntactic arguments (if any) into named and unnamed parameters let curriedCallerArgsOpt, unnamedDelayedCallerArgExprOpt, exprTy = TcMethodApplication_SplitSynArguments cenv env tpenv isProp candidates exprTy curriedCallerArgs mItem @@ -9853,8 +9854,7 @@ and TcMethodApplication | _ -> () 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 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index a82db7ff324..606ff59ebc0 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -1188,28 +1188,7 @@ let execute = IPrintable.Say("hello") |> withLangVersion80 |> typecheck |> shouldSucceed - - [] - let ``Accessing to IWSAM static abstract member produces a compilation error`` () = - Fsx """ -type IPrintable = - static abstract member Log: string -> string -type SomeClass1() = - member this.GetLog(s: string) = IPrintable.Log(s) - - static member Log(s: string) = s - - interface IPrintable with - static member Log(s: string) = s - -let x = IPrintable.Log("hello") - """ - |> withOptions [ "--nowarn:3536" ; "--nowarn:3535" ] - |> withLangVersion80 - |> compile - |> shouldSucceed // TODO: shouldFail - [] let ``Accessing to IWSAM(System.Numerics non virtual) produces a compilation error`` () = Fsx """ From 487f4c73564e83dbb51876315f948c1ae905a7b8 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 25 Nov 2023 13:11:34 +0000 Subject: [PATCH 07/11] Reuse 509 error --- src/Compiler/Checking/CheckExpressions.fs | 15 ++++++--------- src/Compiler/FSComp.txt | 3 +-- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.de.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.es.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.it.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ----- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ----- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 7 ++----- 16 files changed, 9 insertions(+), 81 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index ca00648c4e5..e9a4729a49a 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9846,16 +9846,13 @@ and TcMethodApplication let finalCalledMeth = let callerArgs = { Unnamed = unnamedCurriedCallerArgs ; Named = namedCurriedCallerArgs } - - for minfo, _, _, _ in preArgumentTypeCheckingCalledMethGroup do - match minfo with - | ILMeth(ilMethInfo = ilMethInfo) -> - if ilMethInfo.IsStatic && ilMethInfo.IsAbstract then - errorR(Error(FSComp.SR.chkStaticMembersDirectlyOnInterfaces(), mItem)) - | _ -> () - let postArgumentTypeCheckingCalledMethGroup = - preArgumentTypeCheckingCalledMethGroup |> List.map (fun (minfo, minst, pinfoOpt, usesParamArrayConversion) -> + preArgumentTypeCheckingCalledMethGroup + |> List.filter (fun (minfo, _, _, _) -> + match minfo with + | ILMeth(ilMethInfo = ilMethInfo) -> not(ilMethInfo.IsStatic && ilMethInfo.IsAbstract) + | _ -> true) + |> List.map (fun (minfo, minst, pinfoOpt, usesParamArrayConversion) -> let callerTyArgs = match tyArgsOpt with | Some tyargs -> minfo.AdjustUserTypeInstForFSharpStyleIndexedExtensionMembers tyargs diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index ba6dd7bcbe8..13aa99fd609 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1731,5 +1731,4 @@ featureUnmanagedConstraintCsharpInterop,"Interop between C#'s and F#'s unmanaged 3584,tcDotLambdaAtNotSupportedExpression,"Shorthand lambda syntax is only supported for atomic expressions, such as method, property, field or indexer on the implied '_' argument. For example: 'let f = _.Length'." 3855,tcNoStaticMemberFoundForOverride,"No static abstract member was found that corresponds to this override" 3859,tcNoStaticPropertyFoundForOverride,"No static abstract property was found that corresponds to this override" -3860,chkStaticMembersOnObjectExpressions,"Object expressions cannot implement interfaces with static abstract members or declare static members." -3861,chkStaticMembersDirectlyOnInterfaces,"Interfaces cannot access static abstract members directly." \ No newline at end of file +3860,chkStaticMembersOnObjectExpressions,"Object expressions cannot implement interfaces with static abstract members or declare static members." \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 9949c1fbff8..e00ae35e455 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -122,11 +122,6 @@ Člen nebo funkce „{0}“ má atribut „TailCallAttribute“, ale nepoužívá se koncovým (tail) rekurzivním způsobem. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index c36a6c01720..2ba20dfee57 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -122,11 +122,6 @@ Der Member oder die Funktion "{0}" weist das Attribut "TailCallAttribute" auf, wird jedoch nicht endrekursiv verwendet. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 1a82157ddfd..a240ae2b02a 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -122,11 +122,6 @@ El miembro o la función “{0}” tiene el atributo “TailCallAttribute”, pero no se usa de forma de recursión de cola. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 4cc8b9eff42..6d18837734d 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -122,11 +122,6 @@ Le membre ou la fonction « {0} » possède l'attribut « TailCallAttribute », mais n'est pas utilisé de manière récursive. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index aff6043fa21..d001d237f7b 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -122,11 +122,6 @@ Il membro o la funzione "{0}" ha l'attributo "TailCallAttribute", ma non è in uso in modo ricorsivo finale. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 261e5f1e5a4..95c48ab8f3e 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -122,11 +122,6 @@ メンバーまたは関数 '{0}' には 'TailCallAttribute' 属性がありますが、末尾の再帰的な方法では使用されていません。 - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index d38d1145fd4..6eebf9bf1ff 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -122,11 +122,6 @@ 멤버 또는 함수 '{0}'에 'TailCallAttribute' 특성이 있지만 비상 재귀적인 방식으로 사용되고 있지 않습니다. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 438f47edbc4..e7b4c6348d1 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -122,11 +122,6 @@ Składowa lub funkcja „{0}” ma atrybut „TailCallAttribute”, ale nie jest używana w sposób cykliczny końca. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index f77dfae2f8c..18e45a3e3cb 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -122,11 +122,6 @@ O membro ou a função "{0}" tem o atributo "TailCallAttribute", mas não está sendo usado de maneira recursiva em cauda. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 097324a26f1..39bcb4d4881 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -122,11 +122,6 @@ Элемент или функция "{0}" содержит атрибут "TailCallAttribute", но не используется в рекурсивном хвостовом режиме. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index b82433dfde1..2b41bf7ad5d 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -122,11 +122,6 @@ Üye veya '{0}' işlevi, 'TailCallAttribute' özniteliğine sahip ancak kuyruk özyinelemeli bir şekilde kullanılmıyor. - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index d7e3ec0bb00..ed319784660 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -122,11 +122,6 @@ 成员或函数“{0}”具有 "TailCallAttribute" 属性,但未以尾递归方式使用。 - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index b4e7354af8e..6b693de3830 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -122,11 +122,6 @@ 成員或函式 '{0}' 具有 'TailCallAttribute' 屬性,但未以尾遞迴方式使用。 - - Interfaces cannot access static abstract members directly. - Interfaces cannot access static abstract members directly. - - Object expressions cannot implement interfaces with static abstract members or declare static members. Object expressions cannot implement interfaces with static abstract members or declare static members. diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 606ff59ebc0..0c6dc80cf31 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -920,10 +920,7 @@ let main _ = |> withNoWarn 3535 |> withLangVersion70 |> compile - |> shouldFail - |> withDiagnostics [ - (Error 3861, Line 13, Col 71, Line 13, Col 79, "Interfaces cannot access static abstract members directly.") - ] + |> shouldSucceed [] let ``Produce an error when one leaves out keyword "static" in an implementation of IWSAM`` () = @@ -1200,7 +1197,7 @@ IAdditionOperators.op_Addition (3, 6) |> withLangVersion80 |> compile |> shouldFail - |> withSingleDiagnostic (Error 3861, Line 4, Col 1, Line 4, Col 31, "Interfaces cannot access static abstract members directly.") + |> withSingleDiagnostic (Error 509, Line 4, Col 1, Line 4, Col 38, "Method or object constructor 'op_Addition' not found") [] let ``Accessing to IWSAM(System.Numerics virtual member) compiles and runs`` () = From fc2c61f05e0943d253cf7de661455bee8d7c6bbc Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 10 Apr 2024 15:59:32 +0100 Subject: [PATCH 08/11] Update ResolveOverloading --- src/Compiler/Checking/CheckExpressions.fs | 4 ---- src/Compiler/Checking/ConstraintSolver.fs | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 18bf4364c7b..6c7b88cc7c9 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9957,10 +9957,6 @@ and TcMethodApplication let callerArgs = { Unnamed = unnamedCurriedCallerArgs ; Named = namedCurriedCallerArgs } let postArgumentTypeCheckingCalledMethGroup = preArgumentTypeCheckingCalledMethGroup - |> List.filter (fun (minfo, _, _, _) -> - match minfo with - | ILMeth(ilMethInfo = ilMethInfo) -> not(ilMethInfo.IsStatic && ilMethInfo.IsAbstract) - | _ -> true) |> List.map (fun (minfo, minst, pinfoOpt, usesParamArrayConversion) -> let callerTyArgs = match tyArgsOpt with diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 2667ea6ccfc..948d617d87f 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2936,10 +2936,23 @@ and ResolveOverloading let isOpConversion = (methodName = "op_Explicit") || - (methodName = "op_Implicit") + (methodName = "op_Implicit") || + methodName.Contains("op_") // See what candidates we have based on name and arity - let candidates = calledMethGroup |> List.filter (fun cmeth -> cmeth.IsCandidate(m, ad)) + let candidates = + calledMethGroup + |> List.filter ( + fun cmeth -> + match cmeth.Method with + | ILMeth(ilMethInfo= ilMethInfo) when ilMethInfo.IsStatic && isOpConversion -> + // OK -> static virtual TResult operator checked + // IAdditionOperators.op_CheckedAddition + // Error: static abstract TResult operator + // IAdditionOperators.op_Addition + cmeth.IsCandidate(m, ad) && ilMethInfo.IsVirtual && not ilMethInfo.IsAbstract + | _ -> cmeth.IsCandidate(m, ad) + ) let calledMethOpt, errors, calledMethTrace = @@ -2947,6 +2960,9 @@ and ResolveOverloading | _, [calledMeth] when not isOpConversion -> Some calledMeth, CompleteD, NoTrace + | _, [] when isOpConversion -> + None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), NoTrace + | [], _ when not isOpConversion -> None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), NoTrace From 3ca92e363cfd9d470134f6e08db966ac5f1dc0aa Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 10 Apr 2024 16:02:06 +0100 Subject: [PATCH 09/11] release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index d01125b6b9d..03b678ee4ec 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -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 `[]` 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)) From e79219011f91bf6e6f5469dac78d2a37b368c8ca Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 10 Apr 2024 16:37:31 +0100 Subject: [PATCH 10/11] Update check --- src/Compiler/Checking/ConstraintSolver.fs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 948d617d87f..c8f77df9885 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2936,8 +2936,7 @@ and ResolveOverloading let isOpConversion = (methodName = "op_Explicit") || - (methodName = "op_Implicit") || - methodName.Contains("op_") + (methodName = "op_Implicit") // See what candidates we have based on name and arity let candidates = @@ -2945,7 +2944,7 @@ and ResolveOverloading |> List.filter ( fun cmeth -> match cmeth.Method with - | ILMeth(ilMethInfo= ilMethInfo) when ilMethInfo.IsStatic && isOpConversion -> + | ILMeth(ilMethInfo= ilMethInfo) when ilMethInfo.IsStatic && ilMethInfo.IsVirtual && methodName.Contains("op_") -> // OK -> static virtual TResult operator checked // IAdditionOperators.op_CheckedAddition // Error: static abstract TResult operator @@ -2960,7 +2959,7 @@ and ResolveOverloading | _, [calledMeth] when not isOpConversion -> Some calledMeth, CompleteD, NoTrace - | _, [] when isOpConversion -> + | _, [] when methodName.Contains("op_") -> None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), NoTrace | [], _ when not isOpConversion -> From 328472a651e18d75851e8b380205963c835fe966 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 10 Apr 2024 18:08:26 +0100 Subject: [PATCH 11/11] simplify check --- src/Compiler/Checking/ConstraintSolver.fs | 30 +++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index c8f77df9885..be51f822da3 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2939,28 +2939,22 @@ and ResolveOverloading (methodName = "op_Implicit") // See what candidates we have based on name and arity - let candidates = - calledMethGroup - |> List.filter ( - fun cmeth -> - match cmeth.Method with - | ILMeth(ilMethInfo= ilMethInfo) when ilMethInfo.IsStatic && ilMethInfo.IsVirtual && methodName.Contains("op_") -> - // OK -> static virtual TResult operator checked - // IAdditionOperators.op_CheckedAddition - // Error: static abstract TResult operator - // IAdditionOperators.op_Addition - cmeth.IsCandidate(m, ad) && ilMethInfo.IsVirtual && not ilMethInfo.IsAbstract - | _ -> cmeth.IsCandidate(m, ad) - ) + let candidates = calledMethGroup |> List.filter (fun cmeth -> cmeth.IsCandidate(m, ad)) let calledMethOpt, errors, calledMethTrace = match calledMethGroup, candidates with - | _, [calledMeth] when not isOpConversion -> - Some calledMeth, CompleteD, NoTrace - - | _, [] when methodName.Contains("op_") -> - None, ErrorD (Error (FSComp.SR.csMethodNotFound(methodName), m)), 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