Skip to content

Commit a7ff4a2

Browse files
author
Julien Couvreur
committed
Validate diagnostic ID in Experimental attribute
1 parent d49b29e commit a7ff4a2

17 files changed

+195
-34
lines changed

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7809,4 +7809,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
78097809
<data name="ERR_ExpectedInterpolatedString" xml:space="preserve">
78107810
<value>Expected interpolated string</value>
78117811
</data>
7812+
<data name="ERR_InvalidExperimentalDiagID" xml:space="preserve">
7813+
<value>The argument to the 'Experimental' attribute must be a valid identifier</value>
7814+
</data>
78127815
</root>

src/Compilers/CSharp/Portable/Errors/ErrorCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,8 @@ internal enum ErrorCode
22752275
ERR_InterceptorGlobalNamespace = 9206,
22762276
ERR_InterceptableMethodMustBeOrdinary = 9207,
22772277

2278+
ERR_InvalidExperimentalDiagID = 9208,
2279+
22782280
#endregion
22792281

22802282
// Note: you will need to do the following after adding warnings:

src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ protected void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments<At
226226
return;
227227
}
228228

229+
if (arguments.Attribute.IsTargetAttribute(this, AttributeDescription.ExperimentalAttribute)
230+
&& !SyntaxFacts.IsValidIdentifier((string?)arguments.Attribute.CommonConstructorArguments[0].ValueInternal))
231+
{
232+
arguments.Diagnostics.DiagnosticBag.Add(ErrorCode.ERR_InvalidExperimentalDiagID, arguments.AttributeSyntaxOpt.Location);
233+
return;
234+
}
235+
229236
DecodeWellKnownAttributeImpl(ref arguments);
230237
}
231238
#nullable disable

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)