From 3f3ceec95144ffc790abf94393f8509c4fc736fc Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 10 Jan 2023 13:08:35 +0100 Subject: [PATCH 1/2] Compiler error when implementing interfaces on static classes --- src/Compiler/Checking/CheckDeclarations.fs | 2 ++ 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 +++ .../Language/StaticClassTests.fs | 35 ++++++++++++++++++- 16 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 8a0a5d91a4..a24af31c85 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -1668,6 +1668,8 @@ let private ReportErrorOnStaticClass (synMembers: SynMemberDefn list) = errorR(Error(FSComp.SR.chkInstanceMemberOnStaticClasses(), m)) | SynMemberDefn.LetBindings(isStatic = false; range = range) -> errorR(Error(FSComp.SR.chkInstanceLetBindingOnStaticClasses(), range)) + | SynMemberDefn.Interface(range = range) -> + errorR(Error(FSComp.SR.chkImplementingInterfacesOnStaticClasses(), range)) | _ -> () /// Check and generalize the interface implementations, members, 'let' definitions in a mutually recursive group of definitions. diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 542f45f7fe..4d3678ab38 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1669,4 +1669,5 @@ featureEscapeBracesInFormattableString,"Escapes curly braces before calling Form 3552,chkConstructorWithArgumentsOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Constructor with arguments is not allowed." 3553,chkAdditionalConstructorOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Additional constructor is not allowed." 3554,chkInstanceMemberOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Instance members are not allowed." -3555,chkInstanceLetBindingOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Instance let bindings are not allowed." \ No newline at end of file +3555,chkInstanceLetBindingOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Instance let bindings are not allowed." +3556,chkImplementingInterfacesOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Implementing interfaces is not allowed." \ 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 ba069c5177..d0df5c6d28 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -52,6 +52,11 @@ Funkce {0} vyžaduje knihovnu F# pro verzi jazyka {1} nebo novější. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. Použití := z knihovny F# je zastaralé. Více informací: https://aka.ms/fsharp-refcell-ops. Změňte prosím například cell := expr na cell.Value <- expr. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 89ea05c22d..94204d902c 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -52,6 +52,11 @@ Für das Feature "{0}" ist die F#-Bibliothek für die Sprachversion {1} oder höher erforderlich. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. Die Verwendung von ":=" aus der F#-Bibliothek ist veraltet. Siehe https://aka.ms/fsharp-refcell-ops. Ändern Sie z. B. "cell := expr" in "cell.Value <- expr". diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 9c1f8f44de..5760e2fc90 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -52,6 +52,11 @@ La característica "{0}" requiere la biblioteca de F# para la versión de lenguaje {1} o superior. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. El uso de ":=" de la biblioteca de F# está en desuso. Vea https://aka.ms/fsharp-refcell-ops. Por ejemplo, cambie "cell := expr" a "cell.Value <- expr". diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 41d93aec3b..98f03ba4a1 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -52,6 +52,11 @@ La fonctionnalité '{0}' nécessite la bibliothèque F# pour le langage version {1} ou ultérieure. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. L’utilisation de « := » à partir de la bibliothèque F# est déconseillée. Voir https://aka.ms/fsharp-refcell-ops. Par exemple, veuillez remplacer « cell := expr » par « cell.Value <- expr ». diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 310d3cfed2..0b77e417b4 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -52,6 +52,11 @@ Con la funzionalità '{0}' è richiesta la libreria F# per la versione {1} o successiva del linguaggio. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. L'uso di ':=' dalla libreria F # è deprecato. Vedere https://aka.ms/fsharp-refcell-ops. Ad esempio, modificare 'cell:= expr' in 'cell.Value <- expr'. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 037d187f45..e86766aac7 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -52,6 +52,11 @@ 機能 '{0}' を使用するには、言語バージョン {1} 以上の F# ライブラリが必要です。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. F# ライブラリからの ':=' の使用は非推奨です。https://aka.ms/fsharp-refcell-ops を参照してください。たとえば、'cell : = expr' を 'cell.Value <- expr' に変更してください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 84b210a444..ed1d69bdb6 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -52,6 +52,11 @@ 언어 버전 {1} 이상에서 '{0}' 기능을 사용하려면 F# 라이브러리가 필요합니다. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. F# 라이브러리의 ':=' 사용은 더 이상 사용되지 않습니다. https://aka.ms/fsharp-refcell-ops를 참조하세요. 예를 들어 'cell := expr'을 'cell.Value <- expr'로 변경하세요. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 2922e8a570..3bed7cf76f 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -52,6 +52,11 @@ Funkcja „{0}” wymaga biblioteki języka F# dla wersji językowej {1} lub nowszej. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. Użycie elementu „:=” z biblioteki języka F# jest przestarzałe. Sprawdź stronę https://aka.ms/fsharp-refcell-ops. Na przykład zmień wyrażenie „cell := expr” na „cell.Value <- expr”. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index d3cab9a58e..739e1693df 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -52,6 +52,11 @@ O recurso '{0}' exige a biblioteca F# para a versão da linguagem {1} ou posterior. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. O uso de ':=' da biblioteca F# foi preterido. Consulte https://aka.ms/fsharp-refcell-ops. Por exemplo, altere 'cell := expr' para 'cell.Value <- expr'. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 80ab5cea02..1e244388c0 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -52,6 +52,11 @@ Компоненту "{0}" требуется библиотека F# для языка версии {1} или более поздней. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. Использование ":=" из библиотеки F# является нерекомендуемым. См. https://aka.ms/fsharp-refcell-ops. Например, замените "cell := expr" на "cell.Value <- expr". diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 2b7d71a09a..fcebe2c32a 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -52,6 +52,11 @@ '{0}' özelliği için F# kitaplığının {1} veya üstü dil sürümü gerekir. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. F# kitaplığından gelen ':=' kullanımı kullanım dışı. https://aka.ms/fsharp-refcell-ops’a bakın. Örneğin, lütfen 'cell := expr' ifadesini 'cell.Value <- expr' olarak değiştirin. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index c02a539f37..1523e778f3 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -52,6 +52,11 @@ 功能“{0}”需要 {1} 或更高语言版本的 F# 库。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. 已弃用 F# 库中的“:=”。请参阅 https://aka.ms/fsharp-refcell-ops。 例如,请将“cell := expr”更改为“cell.Value <- expr”。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index b48c8eb8d7..b7219e8204 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -52,6 +52,11 @@ 功能 '{0}' 需要語言版本 {1} 或更高的 F# 程式庫。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed. + + The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'. 透過 F# 程式庫使用 ':=' 的方式已淘汰。請參閱 https://aka.ms/fsharp-refcell-ops。舉例來說,請將 'cell := expr' 變更為 'cell.Value <- expr'。 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs index f96bea3fba..6d71e78f3f 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs @@ -354,4 +354,37 @@ type C() = """ |> withLangVersionPreview |> compile - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type implementing interface in lang 70`` () = + Fsx """ +type MyInterface = + abstract member M : unit -> unit + +[] +type C() = + interface MyInterface with + member this.M() = () + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type implementing interface in lang preview`` () = + Fsx """ +type MyInterface = + abstract member M : unit -> unit + +[] +type C() = + interface MyInterface with + member this.M() = () + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3556, Line 7, Col 5, Line 8, Col 29, "If a type uses both [] and [] attributes, it means it is static. Implementing interfaces is not allowed.") + ] \ No newline at end of file From 4aba47de1fdd05fc0628d832e27c026846795dc3 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 10 Jan 2023 13:24:33 +0100 Subject: [PATCH 2/2] More tests --- .../Language/StaticClassTests.fs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs index 6d71e78f3f..6a8589f5be 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs @@ -371,6 +371,21 @@ type C() = |> compile |> shouldSucceed + [] + let ``Sealed and AbstractClass on a type implicit constructor implementing interface in lang 70`` () = + Fsx """ +type MyInterface = + abstract member M : unit -> unit + +[] +type C = + interface MyInterface with + member this.M() = () + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + [] let ``Sealed and AbstractClass on a type implementing interface in lang preview`` () = Fsx """ @@ -379,6 +394,24 @@ type MyInterface = [] type C() = + interface MyInterface with + member this.M() = () + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3556, Line 7, Col 5, Line 8, Col 29, "If a type uses both [] and [] attributes, it means it is static. Implementing interfaces is not allowed.") + ] + + [] + let ``Sealed and AbstractClass on a type implicit constructor implementing interface in lang preview`` () = + Fsx """ +type MyInterface = + abstract member M : unit -> unit + +[] +type C = interface MyInterface with member this.M() = () """