From 0ce1337c2e90093f41e50d4e49b2718da29de7bc Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 6 Jan 2023 12:27:34 +0000 Subject: [PATCH 1/2] Not constructor arguments are allowed in static classes (#14512) --- src/Compiler/Checking/CheckDeclarations.fs | 27 ++- src/Compiler/FSComp.txt | 5 +- src/Compiler/Facilities/LanguageFeatures.fs | 5 +- src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.de.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.es.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.fr.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.it.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.ja.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.ko.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.pl.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.ru.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.tr.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 15 ++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 15 ++ .../FSharp.Compiler.ComponentTests.fsproj | 1 + .../Language/StaticClassTests.fs | 204 ++++++++++++++++++ 19 files changed, 431 insertions(+), 7 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 4f74ce59c61..f37281a9334 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -1655,6 +1655,17 @@ module MutRecBindingChecking = defnsEs, envMutRec +let private ReportErrorOnStaticClass (synMembers: SynMemberDefn list) = + for mem in synMembers do + match mem with + | SynMemberDefn.ImplicitCtor(ctorArgs = SynSimplePats.SimplePats(pats = pats)) when (not pats.IsEmpty) -> + for pat in pats do + errorR(Error(FSComp.SR.chkConstructorWithArgumentsOnStaticClasses(), pat.Range)) + + | SynMemberDefn.Member(SynBinding(valData = SynValData(memberFlags = Some memberFlags)), m) when memberFlags.MemberKind = SynMemberKind.Constructor -> + errorR(Error(FSComp.SR.chkAdditionalConstructorOnStaticClasses(), m)); + | _ -> () + /// Check and generalize the interface implementations, members, 'let' definitions in a mutually recursive group of definitions. let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (envMutRec: TcEnv) (mutRecDefns: MutRecDefnsPhase2Data) isMutRec = let g = cenv.g @@ -1755,7 +1766,13 @@ let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (env let binds: MutRecDefnsPhase2Info = (envMutRec, mutRecDefns) ||> MutRecShapes.mapTyconsWithEnv (fun envForDecls tyconData -> - let (MutRecDefnsPhase2DataForTycon(tyconOpt, _, declKind, tcref, _, _, declaredTyconTypars, _, _, _, fixupFinalAttrs)) = tyconData + let (MutRecDefnsPhase2DataForTycon(tyconOpt, _x, declKind, tcref, _, _, declaredTyconTypars, synMembers, _, _, fixupFinalAttrs)) = tyconData + + // If a tye uses both [] and [] attributes it means it is a static class. + let isStaticClass = HasFSharpAttribute cenv.g cenv.g.attrib_SealedAttribute tcref.Attribs && HasFSharpAttribute cenv.g cenv.g.attrib_AbstractClassAttribute tcref.Attribs + if isStaticClass && cenv.g.langVersion.SupportsFeature(LanguageFeature.ErrorReportingOnStaticClasses) then + ReportErrorOnStaticClass synMembers + let envForDecls = // This allows to implement protected interface methods if it's a DIM. // Does not need to be hidden behind a lang version as it needs to be possible to @@ -4030,6 +4047,7 @@ module TcDeclarations = let rec private SplitTyconDefn (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) = let extraMembers = desugarGetSetMembers extraMembers let implements1 = List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None) extraMembers + match trepr with | SynTypeDefnRepr.ObjectModel(kind, cspec, m) -> let cspec = desugarGetSetMembers cspec @@ -4047,7 +4065,7 @@ module TcDeclarations = let members = let membersIncludingAutoProps = cspec |> List.filter (fun memb -> - match memb with + match memb with | SynMemberDefn.Interface _ | SynMemberDefn.Member _ | SynMemberDefn.GetSetMember _ @@ -4837,7 +4855,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem let moduleEntity = Construct.NewModuleOrNamespace (Some env.eCompPath) vis id xmlDoc modAttrs (MaybeLazy.Strict moduleTy) // Now typecheck. - let! moduleContents, topAttrsNew, envAtEnd = TcModuleOrNamespaceElements cenv (Parent (mkLocalModuleRef moduleEntity)) endm envForModule xml None [] moduleDefs + let! moduleContents, topAttrsNew, envAtEnd = TcModuleOrNamespaceElements cenv (Parent (mkLocalModuleRef moduleEntity)) endm envForModule xml None [] moduleDefs // Get the inferred type of the decls and record it in the modul. moduleEntity.entity_modul_type <- MaybeLazy.Strict moduleTyAcc.Value @@ -4924,8 +4942,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem let! moduleContents, topAttrs, envAtEnd = TcModuleOrNamespaceElements cenv parent endm envNS xml mutRecNSInfo [] defs - MutRecBindingChecking.TcMutRecDefns_UpdateNSContents nsInfo - + MutRecBindingChecking.TcMutRecDefns_UpdateNSContents nsInfo let env, openDecls = if isNil enclosingNamespacePath then envAtEnd, [] diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 4f05ce235c0..f3093995c52 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1560,6 +1560,7 @@ featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute o featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides" featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [] attribute. Function is not getting inlined." featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals" +featureErrorReportingOnStaticClasses,"Error reporting on static classes" 3353,fsiInvalidDirective,"Invalid directive '#%s %s'" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." @@ -1663,5 +1664,7 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form" 3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data." 3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration" 3550,chkDuplicatedMethodParameter,"Duplicate parameter. The parameter '%s' has been used more that once in this method." +featureEscapeBracesInFormattableString,"Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString" 3551,buildDuplicateFile,"The source file '%s' (at position %d/%d) already appeared in the compilation list (at position %d/%d). Please verify that it is included only once in the project file." -featureEscapeBracesInFormattableString,"Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString" \ No newline at end of file +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." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 7dfedf0be08..e7654bea422 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -60,7 +60,8 @@ type LanguageFeature = | WarningWhenInliningMethodImplNoInlineMarkedFunction | EscapeDotnetFormattableStrings | ArithmeticInLiterals - + | ErrorReportingOnStaticClasses + /// LanguageVersion management type LanguageVersion(versionText) = @@ -136,6 +137,7 @@ type LanguageVersion(versionText) = LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction, previewVersion LanguageFeature.EscapeDotnetFormattableStrings, previewVersion LanguageFeature.ArithmeticInLiterals, previewVersion + LanguageFeature.ErrorReportingOnStaticClasses, previewVersion ] @@ -249,6 +251,7 @@ type LanguageVersion(versionText) = | LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction -> FSComp.SR.featureWarningWhenInliningMethodImplNoInlineMarkedFunction () | LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString () | LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals () + | LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index ac1ae354599..d070a8b4e36 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -50,6 +50,7 @@ type LanguageFeature = | WarningWhenInliningMethodImplNoInlineMarkedFunction | EscapeDotnetFormattableStrings | ArithmeticInLiterals + | ErrorReportingOnStaticClasses /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index a141b854e0e..130db8ee110 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -22,6 +22,16 @@ Soubor {0} má nerozpoznanou příponu. Zdrojové soubory musí mít příponu .fs, .fsi, .fsx nebo .fsscript. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ chyba při zastaralém přístupu konstruktoru s atributem RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 5e40048ccef..b26f864cffd 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -22,6 +22,16 @@ Die Dateierweiterung von „{0}“ wurde nicht erkannt. Quelldateien müssen die Erweiterung .fs, .fsi, .fsx oder .fsscript haben + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ Beim veralteten Zugriff auf das Konstrukt mit dem RequireQualifiedAccess-Attribut wird ein Fehler ausgegeben. + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 1d3aa8f59d9..d16f78b54c6 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -22,6 +22,16 @@ No se reconoce la extensión de archivo de '{0}'. Los archivos de código fuente deben tener las extensiones .fs, .fsi, .fsx o .fsscript + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ error en el acceso en desuso de la construcción con el atributo RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 736d6fd868d..8f6f1db98e5 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -22,6 +22,16 @@ L'extension de fichier de '{0}' n'est pas reconnue. Les fichiers sources doivent avoir l'extension .fs, .fsi, .fsx, ou .fsscript. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ donner une erreur sur l’accès déconseillé de la construction avec l’attribut RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index a8d68906656..ea56b0f7e4a 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -22,6 +22,16 @@ Estensione di file di '{0}' non riconosciuta. I file di origine devono avere estensione .fs, .fsi, .fsx or .fsscript + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ errore durante l'accesso deprecato del costrutto con l'attributo RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index dafb49d0c99..8cda9edc1d7 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -22,6 +22,16 @@ '{0}' のファイル拡張子は認識されません。ソース ファイルの拡張子は .fs、.fsi、.fsx、または .fsscript にする必要があります。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ RequireQualifiedAccess 属性を持つコンストラクトの非推奨アクセスでエラーが発生しました + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 245f2f4fd67..4e77efd30d0 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -22,6 +22,16 @@ '{0}'의 파일 확장명을 인식할 수 없습니다. 원본 파일의 확장명은 .fs, .fsi, .fsx 또는 .fsscript여야 합니다. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ RequireQualifiedAccess 특성을 사용하여 사용되지 않는 구문 액세스에 대한 오류 제공 + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index c3af63d99df..a7033af6dfb 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -22,6 +22,16 @@ Rozszerzenie pliku "{0}" nie zostało rozpoznane. Pliki źródłowe muszą mieć rozszerzenie .fs, .fsi, .fsx lub .fsscript + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ wskazywanie błędu w przypadku przestarzałego dostępu do konstrukcji z atrybutem RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index f6e57da9f52..1c55ec02e84 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -22,6 +22,16 @@ A extensão do arquivo de '{0}' não foi reconhecida. Os arquivos de origem devem ter a extensão .fs, .fsi, .fsx or .fsscript + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ fornecer erro no acesso preterido do constructo com o atributo RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 9e29c3ad79f..157486c8073 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -22,6 +22,16 @@ Расширение файла "{0}" не распознано. Исходные файлы должны иметь расширения FS, FSI, FSX или FSSCRIPT + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ выдать ошибку при устаревшем доступе к конструкции с атрибутом RequireQualifiedAccess + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 29720b597bc..0923ca2d0f7 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -22,6 +22,16 @@ '{0}' kaynak dosyasının dosya uzantısı tanınmadı. Kaynak dosyaların uzantısı .fs, .fsi, .fsx veya .fsscript olmalıdır. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ RequireQualifiedAccess özniteliğine sahip yapının kullanım dışı erişiminde hata + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 54fae5e77e8..3aa9bc0222c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -22,6 +22,16 @@ 无法识别“{0}”的文件扩展名。源文件必须具有扩展名 .fs、.fsi、.fsx 或 .fsscript + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ 对具有 RequireQualifiedAccess 属性的构造进行弃用的访问时出错 + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index e82066b569d..7452751a967 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -22,6 +22,16 @@ 無法辨識 '{0}' 的副檔名。來源檔案的副檔名必須是 .fs、.fsi、.fsx 或 .fsscript。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed. + + + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed. + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicate parameter. The parameter '{0}' has been used more that once in this method. @@ -197,6 +207,11 @@ 對具有 RequireQualifiedAccess 屬性的建構的已取代存取發出錯誤 + + Error reporting on static classes + Error reporting on static classes + + Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 27713b6a4a3..3a00acd4d02 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -177,6 +177,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs new file mode 100644 index 00000000000..c612d762c2b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs @@ -0,0 +1,204 @@ +namespace FSharp.Compiler.ComponentTests.Language + +open Xunit +open FSharp.Test.Compiler + +module StaticClassTests = + + [] + let ``Sealed and AbstractClass on a type in lang version70`` () = + Fsx """ +[] +type T = class end + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type in lang preview`` () = + Fsx """ +[] +type T = class end + """ + |> withLangVersionPreview + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with constructor in lang preview`` () = + Fsx """ +[] +type T() = class end + """ + |> withLangVersionPreview + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with constructor in lang version70`` () = + Fsx """ +[] +type T() = class end + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with constructor with arguments in lang preview`` () = + Fsx """ +[] +type T(x: int) = class end + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3552, Line 3, Col 8, Line 3, Col 14, "If a type uses both [] and [] attributes, it means it is static. Constructor with arguments is not allowed.") + ] + + [] + let ``Sealed and AbstractClass on a type with constructor with arguments in lang version70`` () = + Fsx """ +[] +type T(x: int) = class end + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``When Sealed and AbstractClass on a type with additional constructors in lang preview`` () = + Fsx """ +[] +type T = + new () = {} + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3553, Line 4, Col 5, Line 4, Col 16, "If a type uses both [] and [] attributes, it means it is static. Additional constructor is not allowed.") + ] + + [] + let ``When Sealed and AbstractClass on a type with additional constructors in lang version70`` () = + Fsx """ +[] +type T = + new () = {} + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``When Sealed and AbstractClass on a type with a primary(parameters) and additional constructor in lang preview`` () = + Fsx """ +[] +type T(x: int) = + new () = T(42) + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3552, Line 3, Col 8, Line 3, Col 14, "If a type uses both [] and [] attributes, it means it is static. Constructor with arguments is not allowed.") + (Error 3553, Line 4, Col 5, Line 4, Col 19, "If a type uses both [] and [] attributes, it means it is static. Additional constructor is not allowed.") + ] + + [] + let ``When Sealed and AbstractClass on a type with explicit fields and constructor in lang version70`` () = + Fsx """ +[] +type B = + val F : int + val mutable G : int + new () = { F = 3; G = 3 } + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + [] + let ``When Sealed and AbstractClass on a generic type with constructor in lang version70`` () = + Fsx """ +[] +type ListDebugView<'T>(l: 'T list) = class end + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``When Sealed and AbstractClass on a generic type with constructor in lang preview`` () = + Fsx """ +[] +type ListDebugView<'T>(l: 'T list) = class end + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3552, Line 3, Col 24, Line 3, Col 34, "If a type uses both [] and [] attributes, it means it is static. Constructor with arguments is not allowed.") + ] + + [] + let ``When Sealed and AbstractClass on a type with explicit fields and constructor in lang preview`` () = + Fsx """ +[] +type B = + val F : int + val mutable G : int + new () = { F = 3; G = 3 } + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3553, Line 6, Col 5, Line 6, Col 30, "If a type uses both [] and [] attributes, it means it is static. Additional constructor is not allowed.") + ] + + [] + [] + [] + let ``Mutually recursive type definition that using custom attributes``(langVersion) = + let code = """ + module Test + + open System.Diagnostics + + [] + [>)>] + [] + [] + type MyCustomList<'T> = + | Empty + | NonEmpty of Head: 'T * Tail: MyCustomList<'T> + + and MyImbaAlias<'T> = MyCustomList<'T> + + //------------------------------------------------------------------------- + // List (debug view) + //------------------------------------------------------------------------- + + and + MyCustomListDebugView<'T>(l: MyCustomList<'T>) = + let asList = + let rec toList ml = + match ml with + | Empty -> [] + | NonEmpty (head,tail) -> head :: (toList tail) + toList l + + [] + member x.Items = asList |> List.toArray + + [] + member x._FullList = asList |> List.toArray + + """ + Fs code + |> withLangVersion langVersion + |> compile + |> shouldSucceed \ No newline at end of file From 71cabf4e2cce62b01577609aeb340efa922c8da3 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 9 Jan 2023 08:50:53 +0000 Subject: [PATCH 2/2] Compiler error when using instance members on static class (#14555) * Compiler error when using instance members on static class --- src/Compiler/Checking/CheckDeclarations.fs | 4 +- src/Compiler/FSComp.txt | 1 + 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 | 53 ++++++++++++++++++- 16 files changed, 121 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index f37281a9334..a501f74edc0 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -1663,7 +1663,9 @@ let private ReportErrorOnStaticClass (synMembers: SynMemberDefn list) = errorR(Error(FSComp.SR.chkConstructorWithArgumentsOnStaticClasses(), pat.Range)) | SynMemberDefn.Member(SynBinding(valData = SynValData(memberFlags = Some memberFlags)), m) when memberFlags.MemberKind = SynMemberKind.Constructor -> - errorR(Error(FSComp.SR.chkAdditionalConstructorOnStaticClasses(), m)); + errorR(Error(FSComp.SR.chkAdditionalConstructorOnStaticClasses(), m)) + | SynMemberDefn.Member(SynBinding(valData = SynValData(memberFlags = Some memberFlags)), m) when memberFlags.MemberKind = SynMemberKind.Member && memberFlags.IsInstance -> + errorR(Error(FSComp.SR.chkInstanceMemberOnStaticClasses(), m)); | _ -> () /// 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 f3093995c52..03ab28bfc97 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1668,3 +1668,4 @@ featureEscapeBracesInFormattableString,"Escapes curly braces before calling Form 3551,buildDuplicateFile,"The source file '%s' (at position %d/%d) already appeared in the compilation list (at position %d/%d). Please verify that it is included only once in the project file." 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." diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 130db8ee110..e2477998461 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -72,6 +72,11 @@ Použití incr z knihovny F# je zastaralé. Více informací: https://aka.ms/fsharp-refcell-ops. Změňte prosím například incr cell na cell.Value <- cell.Value + 1. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. Atribut AssemblyKeyNameAttribute je zastaralý. Použijte místo něj AssemblyKeyFileAttribute. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index b26f864cffd..a3d68b6bde1 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -72,6 +72,11 @@ Die Verwendung von "incr" aus der F#-Bibliothek ist veraltet. Siehe https://aka.ms/fsharp-refcell-ops. Ändern Sie z. B. "incr cell" in "cell.Value <- cell.Value + 1". + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. "AssemblyKeyNameAttribute" gilt als veraltet. Verwenden Sie stattdessen "AssemblyKeyFileAttribute". diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index d16f78b54c6..3dcd9a96d4e 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -72,6 +72,11 @@ El uso de "incr" de la biblioteca de F# está en desuso. Vea https://aka.ms/fsharp-refcell-ops. Por ejemplo, cambie "incr cell" a "cell.Value <- cell.Value + 1". + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. El elemento "AssemblyKeyNameAttribute" está en desuso. Use "AssemblyKeyFileAttribute" en su lugar. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 8f6f1db98e5..06bdee98069 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -72,6 +72,11 @@ L’utilisation de « incr » à partir de la bibliothèque F# est déconseillée. Voir https://aka.ms/fsharp-refcell-ops. Par exemple, veuillez remplacer « incr cell » par « cell.Value <- cell.Value + 1 ». + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. 'AssemblyKeyNameAttribute' a été déprécié. Utilisez 'AssemblyKeyFileAttribute' à la place. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index ea56b0f7e4a..6da5546c729 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -72,6 +72,11 @@ L'uso di 'incr' dalla libreria F # è deprecato. Vedere https://aka.ms/fsharp-refcell-ops. Ad esempio, modificare 'incr cell' in 'cell.Value <- cell.Value + 1'. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. L'attributo 'AssemblyKeyNameAttribute' è deprecato. In alternativa, usare 'AssemblyKeyFileAttribute'. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 8cda9edc1d7..2a493955d6f 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -72,6 +72,11 @@ F# ライブラリからの 'incr' の使用は非推奨です。https://aka.ms/fsharp-refcell-ops を参照してください。たとえば、'incr cell' を 'cell.Value <- cell.Value +1' に変更してください。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. 'AssemblyKeyNameAttribute' は非推奨になりました。代わりに 'AssemblyKeyFileAttribute' を使用してください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 4e77efd30d0..ef266833a3d 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -72,6 +72,11 @@ F# 라이브러리의 'incr' 사용은 더 이상 사용되지 않습니다. https://aka.ms/fsharp-refcell-ops를 참조하세요. 예를 들어 'incr cell'을 'cell.Value <- cell.Value + 1'로 변경하세요. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. 'AssemblyKeyNameAttribute'는 사용되지 않습니다. 대신 'AssemblyKeyFileAttribute'를 사용하세요. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index a7033af6dfb..9ac9aab7e10 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -72,6 +72,11 @@ Użycie elementu „incr” z biblioteki języka F# jest przestarzałe. Sprawdź stronę https://aka.ms/fsharp-refcell-ops. Na przykład zmień wyrażenie „incr cell” na „cell.Value <- cell.Value + 1”. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. Element „AssemblyKeyNameAttribute” jest przestarzały. Zamiast niego użyj elementu „AssemblyKeyFileAttribute”. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 1c55ec02e84..15594c8ad01 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -72,6 +72,11 @@ O uso de 'incr' da biblioteca F# foi preterido. Consulte https://aka.ms/fsharp-refcell-ops. Por exemplo, altere a célula 'incr cell' para 'cell.Value <- cell.Value + 1'. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. O 'AssemblyKeyNameAttribute' foi preterido. Use o 'AssemblyKeyFileAttribute'. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 157486c8073..5da5e9edb15 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -72,6 +72,11 @@ Использование "incr" из библиотеки F# является нерекомендуемым. См. https://aka.ms/fsharp-refcell-ops. Например, замените "incr cell" на "cell.Value <- cell.Value + 1". + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. Атрибут "AssemblyKeyNameAttribute" является устаревшим. Используйте вместо него атрибут "AssemblyKeyFileAttribute". diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 0923ca2d0f7..9cbd059ab60 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -72,6 +72,11 @@ F# kitaplığından gelen 'incr' kullanımı kullanım dışı. https://aka.ms/fsharp-refcell-ops’a bakın. Örneğin, lütfen 'incr cell' ifadesini 'cell.Value <- cell.Value + 1' olarak değiştirin. + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. 'AssemblyKeyNameAttribute' kullanım dışı bırakıldı. Bunun yerine 'AssemblyKeyFileAttribute' kullanın. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 3aa9bc0222c..f01de0338e6 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -72,6 +72,11 @@ 已弃用 F# 库中的“incr”。请参阅 https://aka.ms/fsharp-refcell-ops。 例如,请将“incr cell”更改为“cell.Value <- cell.Value + 1”。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. "AssemblyKeyNameAttribute" 已被弃用。请改为使用 "AssemblyKeyFileAttribute"。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 7452751a967..8d34c0cf216 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -72,6 +72,11 @@ 透過 F# 程式庫使用 'incr' 的方式已淘汰。請參閱 https://aka.ms/fsharp-refcell-ops。舉例來說,請將 'incr cell' 變更為 'cell.Value <- cell.Value + 1'。 + + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed. + + The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead. 'AssemblyKeyNameAttribute' 已淘汰。請改用 'AssemblyKeyFileAttribute'。 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs index c612d762c2b..b6a2f32e2f1 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/StaticClassTests.fs @@ -201,4 +201,55 @@ type B = Fs code |> withLangVersion langVersion |> compile - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with instance members in lang version70`` () = + Fsx """ +[] +type T() = + member this.M() = () + static member X = 1 + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with instance members in lang preview`` () = + Fsx """ +[] +type T() = + member this.M() = () + static member X = 1 + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 3554, Line 4, Col 5, Line 4, Col 25, "If a type uses both [] and [] attributes, it means it is static. Instance members are not allowed.") + ] + + [] + let ``Sealed and AbstractClass on a type with static members in lang version70`` () = + Fsx """ +[] +type T() = + static member M() = () + static member X = T.M() + """ + |> withLangVersion70 + |> compile + |> shouldSucceed + + [] + let ``Sealed and AbstractClass on a type with static members in lang preview`` () = + Fsx """ +[] +type T() = + static member M() = () + static member X = T.M() + """ + |> withLangVersionPreview + |> compile + |> shouldSucceed \ No newline at end of file