Skip to content

Commit 9d747c9

Browse files
authored
Limit language version on Logger and Options source gens (#90654)
1 parent bb76be2 commit 9d747c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+876
-454
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
142142
| __`SYSLIB1023`__ | Generating more than 6 arguments is not supported |
143143
| __`SYSLIB1024`__ | Argument is using the unsupported out parameter modifier |
144144
| __`SYSLIB1025`__ | Multiple logging methods cannot use the same event name within a class |
145-
| __`SYSLIB1026`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
146-
| __`SYSLIB1027`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
147-
| __`SYSLIB1028`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
148-
| __`SYSLIB1029`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
145+
| __`SYSLIB1026`__ | C# language version not supported by the logging source generator. |
146+
| __`SYSLIB1027`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
147+
| __`SYSLIB1028`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
148+
| __`SYSLIB1029`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
149149
| __`SYSLIB1030`__ | JsonSourceGenerator did not generate serialization metadata for type |
150150
| __`SYSLIB1031`__ | JsonSourceGenerator encountered a duplicate JsonTypeInfo property name |
151151
| __`SYSLIB1032`__ | JsonSourceGenerator encountered a context class that is not partial |
@@ -250,7 +250,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
250250
| __`SYSLIB1213`__ | Options validation generator: Member potentially missing enumerable validation. |
251251
| __`SYSLIB1214`__ | Options validation generator: Can't validate constants, static fields or properties. |
252252
| __`SYSLIB1215`__ | Options validation generator: Validation attribute on the member is inaccessible from the validator type. |
253-
| __`SYSLIB1216`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
253+
| __`SYSLIB1216`__ | C# language version not supported by the options validation source generator. |
254254
| __`SYSLIB1217`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
255255
| __`SYSLIB1218`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
256256
| __`SYSLIB1219`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/DiagnosticDescriptors.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,13 @@ public static class DiagnosticDescriptors
200200
category: "LoggingGenerator",
201201
DiagnosticSeverity.Warning,
202202
isEnabledByDefault: true);
203+
204+
public static DiagnosticDescriptor LoggingUnsupportedLanguageVersion { get; } = new DiagnosticDescriptor(
205+
id: "SYSLIB1026",
206+
title: new LocalizableResourceString(nameof(SR.LoggingUnsupportedLanguageVersionTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
207+
messageFormat: new LocalizableResourceString(nameof(SR.LoggingUnsupportedLanguageVersionMessageFormat), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
208+
category: "LoggingGenerator",
209+
defaultSeverity: DiagnosticSeverity.Error,
210+
isEnabledByDefault: true);
203211
}
204212
}

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ static bool IsAllowedKind(SyntaxKind kind) =>
591591
}
592592
}
593593

594+
if (results.Count > 0 && _compilation is CSharpCompilation { LanguageVersion : LanguageVersion version and < LanguageVersion.CSharp8 })
595+
{
596+
// we only support C# 8.0 and above
597+
Diag(DiagnosticDescriptors.LoggingUnsupportedLanguageVersion, null, version.ToDisplayString(), LanguageVersion.CSharp8.ToDisplayString());
598+
return Array.Empty<LoggerClass>();
599+
}
600+
594601
return results;
595602
}
596603

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,10 @@
231231
<data name="MalformedFormatStringsTitle" xml:space="preserve">
232232
<value>Logging method contains malformed format strings</value>
233233
</data>
234+
<data name="LoggingUnsupportedLanguageVersionTitle" xml:space="preserve">
235+
<value>C# language version not supported by the source generator.</value>
236+
</data>
237+
<data name="LoggingUnsupportedLanguageVersionMessageFormat" xml:space="preserve">
238+
<value>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</value>
239+
</data>
234240
</root>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.cs.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">Metody protokolování musí být statické.</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">Metoda protokolování {0} obsahuje řetězce s poškozeným formátem.</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.de.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">Protokollierungsmethoden müssen statisch sein.</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">Die Protokollierungsmethode „{0}“ enthält nicht wohlgeformte Formatzeichenfolgen.</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.es.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">Los métodos de registro deben ser estáticos</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">El método de registro “{0}” contiene cadenas con formato incorrecto</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.fr.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">Les méthodes de journalisation doivent être statiques</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">La méthode de journalisation « {0} »contient des chaînes de format incorrectes</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.it.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">I metodi di registrazione devono essere statici</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">Il metodo di registrazione '{0}' contiene stringhe in formato non valido</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.ja.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
<target state="translated">ログ メソッドは静的である必要があります</target>
6868
<note />
6969
</trans-unit>
70+
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
71+
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
72+
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
73+
<note />
74+
</trans-unit>
75+
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
76+
<source>C# language version not supported by the source generator.</source>
77+
<target state="new">C# language version not supported by the source generator.</target>
78+
<note />
79+
</trans-unit>
7080
<trans-unit id="MalformedFormatStringsMessage">
7181
<source>Logging method '{0}' contains malformed format strings</source>
7282
<target state="translated">ログ メソッド '{0}' に、形式の正しくない文字列が含まれています</target>

0 commit comments

Comments
 (0)