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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,19 @@ 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))
| 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.
let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (envMutRec: TcEnv) (mutRecDefns: MutRecDefnsPhase2Data) isMutRec =
let g = cenv.g
Expand Down Expand Up @@ -1755,7 +1768,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 [<Sealed>] and [<AbstractClass>] 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
Expand Down Expand Up @@ -4030,6 +4049,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
Expand All @@ -4047,7 +4067,7 @@ module TcDeclarations =
let members =
let membersIncludingAutoProps =
cspec |> List.filter (fun memb ->
match memb with
match memb with
| SynMemberDefn.Interface _
| SynMemberDefn.Member _
| SynMemberDefn.GetSetMember _
Expand Down Expand Up @@ -4837,7 +4857,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
Expand Down Expand Up @@ -4924,8 +4944,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, []
Expand Down
6 changes: 5 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<MethodImpl(MethodImplOptions.NoInlining)>] 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."
Expand Down Expand Up @@ -1663,5 +1664,8 @@ 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"
3552,chkConstructorWithArgumentsOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed."
3553,chkAdditionalConstructorOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed."
3554,chkInstanceMemberOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed."
5 changes: 4 additions & 1 deletion src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ type LanguageFeature =
| WarningWhenInliningMethodImplNoInlineMarkedFunction
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals

| ErrorReportingOnStaticClasses

/// LanguageVersion management
type LanguageVersion(versionText) =

Expand Down Expand Up @@ -136,6 +137,7 @@ type LanguageVersion(versionText) =
LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction, previewVersion
LanguageFeature.EscapeDotnetFormattableStrings, previewVersion
LanguageFeature.ArithmeticInLiterals, previewVersion
LanguageFeature.ErrorReportingOnStaticClasses, previewVersion

]

Expand Down Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type LanguageFeature =
| WarningWhenInliningMethodImplNoInlineMarkedFunction
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals
| ErrorReportingOnStaticClasses

/// LanguageVersion management
type LanguageVersion =
Expand Down
20 changes: 20 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<target state="translated">Soubor {0} má nerozpoznanou příponu. Zdrojové soubory musí mít příponu .fs, .fsi, .fsx nebo .fsscript.</target>
<note />
</trans-unit>
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkDuplicatedMethodParameter">
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
<target state="translated">Duplicitní parametr Parametr {0} byl v této metodě použit vícekrát.</target>
Expand Down Expand Up @@ -62,6 +72,11 @@
<target state="translated">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 &lt;- cell.Value + 1.</target>
<note />
</trans-unit>
<trans-unit id="chkInstanceMemberOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</target>
<note />
</trans-unit>
<trans-unit id="containerDeprecated">
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
<target state="translated">Atribut AssemblyKeyNameAttribute je zastaralý. Použijte místo něj AssemblyKeyFileAttribute.</target>
Expand Down Expand Up @@ -197,6 +212,11 @@
<target state="translated">chyba při zastaralém přístupu konstruktoru s atributem RequireQualifiedAccess</target>
<note />
</trans-unit>
<trans-unit id="featureErrorReportingOnStaticClasses">
<source>Error reporting on static classes</source>
<target state="new">Error reporting on static classes</target>
<note />
</trans-unit>
<trans-unit id="featureEscapeBracesInFormattableString">
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
<target state="translated">Uvede složené závorky před voláním formattableStringFactory.Create, pokud je interpolovaný řetězcový literál zadán jako FormattableString.</target>
Expand Down
20 changes: 20 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<target state="translated">Die Dateierweiterung von „{0}“ wurde nicht erkannt. Quelldateien müssen die Erweiterung .fs, .fsi, .fsx oder .fsscript haben</target>
<note />
</trans-unit>
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkDuplicatedMethodParameter">
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
<target state="translated">Doppelter Parameter. Der Parameter „{0}“ wurde in dieser Methode mehrmals verwendet.</target>
Expand Down Expand Up @@ -62,6 +72,11 @@
<target state="translated">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 &lt;- cell.Value + 1".</target>
<note />
</trans-unit>
<trans-unit id="chkInstanceMemberOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</target>
<note />
</trans-unit>
<trans-unit id="containerDeprecated">
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
<target state="translated">"AssemblyKeyNameAttribute" gilt als veraltet. Verwenden Sie stattdessen "AssemblyKeyFileAttribute".</target>
Expand Down Expand Up @@ -197,6 +212,11 @@
<target state="translated">Beim veralteten Zugriff auf das Konstrukt mit dem RequireQualifiedAccess-Attribut wird ein Fehler ausgegeben.</target>
<note />
</trans-unit>
<trans-unit id="featureErrorReportingOnStaticClasses">
<source>Error reporting on static classes</source>
<target state="new">Error reporting on static classes</target>
<note />
</trans-unit>
<trans-unit id="featureEscapeBracesInFormattableString">
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
<target state="translated">Escapezeichen mit geschweiften Klammern, bevor FormattableStringFactory.Create aufgerufen wird, wenn ein interpoliertes Zeichenfolgenliteral als FormattableString eingegeben wird.</target>
Expand Down
20 changes: 20 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<target state="translated">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</target>
<note />
</trans-unit>
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Additional constructor is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Constructor with arguments is not allowed.</target>
<note />
</trans-unit>
<trans-unit id="chkDuplicatedMethodParameter">
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
<target state="translated">Parámetro duplicado. El parámetro '{0}' se ha usado más una vez en este método.</target>
Expand Down Expand Up @@ -62,6 +72,11 @@
<target state="translated">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 &lt;- cell.Value + 1".</target>
<note />
</trans-unit>
<trans-unit id="chkInstanceMemberOnStaticClasses">
<source>If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</source>
<target state="new">If a type uses both [&lt;Sealed&gt;] and [&lt;AbstractClass&gt;] attributes, it means it is static. Instance members are not allowed.</target>
<note />
</trans-unit>
<trans-unit id="containerDeprecated">
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
<target state="translated">El elemento "AssemblyKeyNameAttribute" está en desuso. Use "AssemblyKeyFileAttribute" en su lugar.</target>
Expand Down Expand Up @@ -197,6 +212,11 @@
<target state="translated">error en el acceso en desuso de la construcción con el atributo RequireQualifiedAccess</target>
<note />
</trans-unit>
<trans-unit id="featureErrorReportingOnStaticClasses">
<source>Error reporting on static classes</source>
<target state="new">Error reporting on static classes</target>
<note />
</trans-unit>
<trans-unit id="featureEscapeBracesInFormattableString">
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
<target state="translated">Crea un escape de llaves antes de llamar a FormattableStringFactory.Create cuando el literal de cadena interpolado se escribe como FormattableString.</target>
Expand Down
Loading