Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
07e91a9
Not constructor arguments are allowed in static classes
edgarfgp Dec 25, 2022
1749af9
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Dec 27, 2022
ecb0363
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Dec 28, 2022
656d4aa
More tests
edgarfgp Dec 28, 2022
f4a332b
Merge branch 'compiler-warning-when-constructor-arguments-in-static-c…
edgarfgp Dec 28, 2022
63b8595
Repro of failing bootstrap build added
T-Gro Dec 29, 2022
335da6e
Make it work for langversion 7.0 at least
T-Gro Dec 29, 2022
c17acae
Fix the general case, leaving out a comment of what is wrong => this …
T-Gro Dec 29, 2022
9df0f50
Move the static elements check after the type check
edgarfgp Dec 29, 2022
79b01cf
Move the static class check where attributes are no longer SynAttrs, …
edgarfgp Jan 2, 2023
914f4cf
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Jan 2, 2023
ba89f41
Update FSComp to include a new error message
edgarfgp Jan 3, 2023
dd40362
Use the new error messages
edgarfgp Jan 3, 2023
2f88aa4
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Jan 3, 2023
3c68a01
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Jan 4, 2023
9aa8cff
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Jan 5, 2023
ba23435
Update src/Compiler/Checking/CheckDeclarations.fs
edgarfgp Jan 5, 2023
5c14b05
Fix capitalization
edgarfgp Jan 5, 2023
0a957f2
Merge branch 'main' into compiler-warning-when-constructor-arguments-…
edgarfgp Jan 5, 2023
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
27 changes: 22 additions & 5 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [<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 +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
Expand All @@ -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 _
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, []
Expand Down
5 changes: 4 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,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"
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."
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
15 changes: 15 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="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
Expand Down Expand Up @@ -197,6 +207,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="new">Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</target>
Expand Down
15 changes: 15 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="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
Expand Down Expand Up @@ -197,6 +207,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="new">Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</target>
Expand Down
15 changes: 15 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="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
Expand Down Expand Up @@ -197,6 +207,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="new">Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<target state="translated">L'extension de fichier de '{0}' n'est pas reconnue. Les fichiers sources doivent avoir l'extension .fs, .fsi, .fsx, ou .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="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
Expand Down Expand Up @@ -197,6 +207,11 @@
<target state="translated">donner une erreur sur l’accès déconseillé de la construction avec l’attribut 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="new">Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<target state="translated">Estensione di file di '{0}' non riconosciuta. I file di origine devono avere estensione .fs, .fsi, .fsx or .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="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
Expand Down Expand Up @@ -197,6 +207,11 @@
<target state="translated">errore durante l'accesso deprecato del costrutto con l'attributo 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="new">Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</target>
Expand Down
Loading