Skip to content

Commit d7ebfd6

Browse files
authored
Merge pull request #14558 from dotnet/merges/main-to-release/dev17.5
Merge main to release/dev17.5
2 parents c9d55e3 + 9883a1c commit d7ebfd6

19 files changed

+550
-7
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,19 @@ module MutRecBindingChecking =
16551655

16561656
defnsEs, envMutRec
16571657

1658+
let private ReportErrorOnStaticClass (synMembers: SynMemberDefn list) =
1659+
for mem in synMembers do
1660+
match mem with
1661+
| SynMemberDefn.ImplicitCtor(ctorArgs = SynSimplePats.SimplePats(pats = pats)) when (not pats.IsEmpty) ->
1662+
for pat in pats do
1663+
errorR(Error(FSComp.SR.chkConstructorWithArgumentsOnStaticClasses(), pat.Range))
1664+
1665+
| SynMemberDefn.Member(SynBinding(valData = SynValData(memberFlags = Some memberFlags)), m) when memberFlags.MemberKind = SynMemberKind.Constructor ->
1666+
errorR(Error(FSComp.SR.chkAdditionalConstructorOnStaticClasses(), m))
1667+
| SynMemberDefn.Member(SynBinding(valData = SynValData(memberFlags = Some memberFlags)), m) when memberFlags.MemberKind = SynMemberKind.Member && memberFlags.IsInstance ->
1668+
errorR(Error(FSComp.SR.chkInstanceMemberOnStaticClasses(), m));
1669+
| _ -> ()
1670+
16581671
/// Check and generalize the interface implementations, members, 'let' definitions in a mutually recursive group of definitions.
16591672
let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (envMutRec: TcEnv) (mutRecDefns: MutRecDefnsPhase2Data) isMutRec =
16601673
let g = cenv.g
@@ -1755,7 +1768,13 @@ let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (env
17551768

17561769
let binds: MutRecDefnsPhase2Info =
17571770
(envMutRec, mutRecDefns) ||> MutRecShapes.mapTyconsWithEnv (fun envForDecls tyconData ->
1758-
let (MutRecDefnsPhase2DataForTycon(tyconOpt, _, declKind, tcref, _, _, declaredTyconTypars, _, _, _, fixupFinalAttrs)) = tyconData
1771+
let (MutRecDefnsPhase2DataForTycon(tyconOpt, _x, declKind, tcref, _, _, declaredTyconTypars, synMembers, _, _, fixupFinalAttrs)) = tyconData
1772+
1773+
// If a tye uses both [<Sealed>] and [<AbstractClass>] attributes it means it is a static class.
1774+
let isStaticClass = HasFSharpAttribute cenv.g cenv.g.attrib_SealedAttribute tcref.Attribs && HasFSharpAttribute cenv.g cenv.g.attrib_AbstractClassAttribute tcref.Attribs
1775+
if isStaticClass && cenv.g.langVersion.SupportsFeature(LanguageFeature.ErrorReportingOnStaticClasses) then
1776+
ReportErrorOnStaticClass synMembers
1777+
17591778
let envForDecls =
17601779
// This allows to implement protected interface methods if it's a DIM.
17611780
// Does not need to be hidden behind a lang version as it needs to be possible to
@@ -4030,6 +4049,7 @@ module TcDeclarations =
40304049
let rec private SplitTyconDefn (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) =
40314050
let extraMembers = desugarGetSetMembers extraMembers
40324051
let implements1 = List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None) extraMembers
4052+
40334053
match trepr with
40344054
| SynTypeDefnRepr.ObjectModel(kind, cspec, m) ->
40354055
let cspec = desugarGetSetMembers cspec
@@ -4047,7 +4067,7 @@ module TcDeclarations =
40474067
let members =
40484068
let membersIncludingAutoProps =
40494069
cspec |> List.filter (fun memb ->
4050-
match memb with
4070+
match memb with
40514071
| SynMemberDefn.Interface _
40524072
| SynMemberDefn.Member _
40534073
| SynMemberDefn.GetSetMember _
@@ -4837,7 +4857,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
48374857
let moduleEntity = Construct.NewModuleOrNamespace (Some env.eCompPath) vis id xmlDoc modAttrs (MaybeLazy.Strict moduleTy)
48384858

48394859
// Now typecheck.
4840-
let! moduleContents, topAttrsNew, envAtEnd = TcModuleOrNamespaceElements cenv (Parent (mkLocalModuleRef moduleEntity)) endm envForModule xml None [] moduleDefs
4860+
let! moduleContents, topAttrsNew, envAtEnd = TcModuleOrNamespaceElements cenv (Parent (mkLocalModuleRef moduleEntity)) endm envForModule xml None [] moduleDefs
48414861

48424862
// Get the inferred type of the decls and record it in the modul.
48434863
moduleEntity.entity_modul_type <- MaybeLazy.Strict moduleTyAcc.Value
@@ -4924,8 +4944,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
49244944

49254945
let! moduleContents, topAttrs, envAtEnd = TcModuleOrNamespaceElements cenv parent endm envNS xml mutRecNSInfo [] defs
49264946

4927-
MutRecBindingChecking.TcMutRecDefns_UpdateNSContents nsInfo
4928-
4947+
MutRecBindingChecking.TcMutRecDefns_UpdateNSContents nsInfo
49294948
let env, openDecls =
49304949
if isNil enclosingNamespacePath then
49314950
envAtEnd, []

src/Compiler/FSComp.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute o
15601560
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
15611561
featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined."
15621562
featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals"
1563+
featureErrorReportingOnStaticClasses,"Error reporting on static classes"
15631564
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
15641565
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
15651566
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,8 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form"
16631664
3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data."
16641665
3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration"
16651666
3550,chkDuplicatedMethodParameter,"Duplicate parameter. The parameter '%s' has been used more that once in this method."
1667+
featureEscapeBracesInFormattableString,"Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString"
16661668
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."
1667-
featureEscapeBracesInFormattableString,"Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString"
1669+
3552,chkConstructorWithArgumentsOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Constructor with arguments is not allowed."
1670+
3553,chkAdditionalConstructorOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Additional constructor is not allowed."
1671+
3554,chkInstanceMemberOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance members are not allowed."

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ type LanguageFeature =
6060
| WarningWhenInliningMethodImplNoInlineMarkedFunction
6161
| EscapeDotnetFormattableStrings
6262
| ArithmeticInLiterals
63-
63+
| ErrorReportingOnStaticClasses
64+
6465
/// LanguageVersion management
6566
type LanguageVersion(versionText) =
6667

@@ -136,6 +137,7 @@ type LanguageVersion(versionText) =
136137
LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction, previewVersion
137138
LanguageFeature.EscapeDotnetFormattableStrings, previewVersion
138139
LanguageFeature.ArithmeticInLiterals, previewVersion
140+
LanguageFeature.ErrorReportingOnStaticClasses, previewVersion
139141

140142
]
141143

@@ -249,6 +251,7 @@ type LanguageVersion(versionText) =
249251
| LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction -> FSComp.SR.featureWarningWhenInliningMethodImplNoInlineMarkedFunction ()
250252
| LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString ()
251253
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
254+
| LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses ()
252255

253256
/// Get a version string associated with the given feature.
254257
static member GetFeatureVersionString feature =

src/Compiler/Facilities/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type LanguageFeature =
5050
| WarningWhenInliningMethodImplNoInlineMarkedFunction
5151
| EscapeDotnetFormattableStrings
5252
| ArithmeticInLiterals
53+
| ErrorReportingOnStaticClasses
5354

5455
/// LanguageVersion management
5556
type LanguageVersion =

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<target state="translated">Soubor {0} má nerozpoznanou příponu. Zdrojové soubory musí mít příponu .fs, .fsi, .fsx nebo .fsscript.</target>
2323
<note />
2424
</trans-unit>
25+
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
26+
<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>
27+
<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>
28+
<note />
29+
</trans-unit>
30+
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
31+
<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>
32+
<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>
33+
<note />
34+
</trans-unit>
2535
<trans-unit id="chkDuplicatedMethodParameter">
2636
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
2737
<target state="translated">Duplicitní parametr Parametr {0} byl v této metodě použit vícekrát.</target>
@@ -62,6 +72,11 @@
6272
<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>
6373
<note />
6474
</trans-unit>
75+
<trans-unit id="chkInstanceMemberOnStaticClasses">
76+
<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>
77+
<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>
78+
<note />
79+
</trans-unit>
6580
<trans-unit id="containerDeprecated">
6681
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
6782
<target state="translated">Atribut AssemblyKeyNameAttribute je zastaralý. Použijte místo něj AssemblyKeyFileAttribute.</target>
@@ -197,6 +212,11 @@
197212
<target state="translated">chyba při zastaralém přístupu konstruktoru s atributem RequireQualifiedAccess</target>
198213
<note />
199214
</trans-unit>
215+
<trans-unit id="featureErrorReportingOnStaticClasses">
216+
<source>Error reporting on static classes</source>
217+
<target state="new">Error reporting on static classes</target>
218+
<note />
219+
</trans-unit>
200220
<trans-unit id="featureEscapeBracesInFormattableString">
201221
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
202222
<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>

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<target state="translated">Die Dateierweiterung von „{0}“ wurde nicht erkannt. Quelldateien müssen die Erweiterung .fs, .fsi, .fsx oder .fsscript haben</target>
2323
<note />
2424
</trans-unit>
25+
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
26+
<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>
27+
<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>
28+
<note />
29+
</trans-unit>
30+
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
31+
<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>
32+
<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>
33+
<note />
34+
</trans-unit>
2535
<trans-unit id="chkDuplicatedMethodParameter">
2636
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
2737
<target state="translated">Doppelter Parameter. Der Parameter „{0}“ wurde in dieser Methode mehrmals verwendet.</target>
@@ -62,6 +72,11 @@
6272
<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>
6373
<note />
6474
</trans-unit>
75+
<trans-unit id="chkInstanceMemberOnStaticClasses">
76+
<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>
77+
<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>
78+
<note />
79+
</trans-unit>
6580
<trans-unit id="containerDeprecated">
6681
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
6782
<target state="translated">"AssemblyKeyNameAttribute" gilt als veraltet. Verwenden Sie stattdessen "AssemblyKeyFileAttribute".</target>
@@ -197,6 +212,11 @@
197212
<target state="translated">Beim veralteten Zugriff auf das Konstrukt mit dem RequireQualifiedAccess-Attribut wird ein Fehler ausgegeben.</target>
198213
<note />
199214
</trans-unit>
215+
<trans-unit id="featureErrorReportingOnStaticClasses">
216+
<source>Error reporting on static classes</source>
217+
<target state="new">Error reporting on static classes</target>
218+
<note />
219+
</trans-unit>
200220
<trans-unit id="featureEscapeBracesInFormattableString">
201221
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
202222
<target state="translated">Escapezeichen mit geschweiften Klammern, bevor FormattableStringFactory.Create aufgerufen wird, wenn ein interpoliertes Zeichenfolgenliteral als FormattableString eingegeben wird.</target>

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<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>
2323
<note />
2424
</trans-unit>
25+
<trans-unit id="chkAdditionalConstructorOnStaticClasses">
26+
<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>
27+
<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>
28+
<note />
29+
</trans-unit>
30+
<trans-unit id="chkConstructorWithArgumentsOnStaticClasses">
31+
<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>
32+
<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>
33+
<note />
34+
</trans-unit>
2535
<trans-unit id="chkDuplicatedMethodParameter">
2636
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
2737
<target state="translated">Parámetro duplicado. El parámetro '{0}' se ha usado más una vez en este método.</target>
@@ -62,6 +72,11 @@
6272
<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>
6373
<note />
6474
</trans-unit>
75+
<trans-unit id="chkInstanceMemberOnStaticClasses">
76+
<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>
77+
<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>
78+
<note />
79+
</trans-unit>
6580
<trans-unit id="containerDeprecated">
6681
<source>The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead.</source>
6782
<target state="translated">El elemento "AssemblyKeyNameAttribute" está en desuso. Use "AssemblyKeyFileAttribute" en su lugar.</target>
@@ -197,6 +212,11 @@
197212
<target state="translated">error en el acceso en desuso de la construcción con el atributo RequireQualifiedAccess</target>
198213
<note />
199214
</trans-unit>
215+
<trans-unit id="featureErrorReportingOnStaticClasses">
216+
<source>Error reporting on static classes</source>
217+
<target state="new">Error reporting on static classes</target>
218+
<note />
219+
</trans-unit>
200220
<trans-unit id="featureEscapeBracesInFormattableString">
201221
<source>Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString</source>
202222
<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>

0 commit comments

Comments
 (0)