-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No validation for pre-processor symbols in C# Parse Options, and report multiple errors #16920
No validation for pre-processor symbols in C# Parse Options, and report multiple errors #16920
Conversation
@@ -3263,7 +3263,6 @@ override Microsoft.CodeAnalysis.CSharp.Syntax.XmlTextSyntax.Accept<TResult>(Micr | |||
override Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor visitor) -> void | |||
override Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax.Accept<TResult>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult> visitor) -> TResult | |||
static Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser.Default.get -> Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser | |||
static Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser.ParseConditionalCompilationSymbols(string value, out System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Diagnostic> diagnostics) -> System.Collections.Generic.IEnumerable<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this actually shipped? If so, this is a binary breaking change. #Resolved
@CyrusNajmabadi @jaredpar @dotnet/roslyn-compat-council
Is there a reason that this specific |
First, let's find out when that API was added. If it was between 2015 and 2017, we can remove it. However, if it's been shipped from before 2017, then we basically can't remove it. Talk to @jaredpar if you want more info on our exceptionally high breaking-change bar. #Resolved |
Assert.Throws<ArgumentException>(() => new CSharpParseOptions(preprocessorSymbols: ImmutableArray.Create<string>("Good", null, @"Bad\Symbol"))); | ||
var options = new CSharpParseOptions(preprocessorSymbols: new string[] { "valid1", "2invalid" }); | ||
|
||
Assert.Equal(2, options.PreprocessorSymbolNames.Count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is an AssertEx.Equal
overload that could be used for this comparison, and the one in the following test. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API changes reverted, per general guidance from team. |
@@ -1470,7 +1470,7 @@ private ImmutableArray<string> BuildSearchPaths(string sdkDirectoryOpt, List<str | |||
|
|||
public static IEnumerable<string> ParseConditionalCompilationSymbols(string value, out IEnumerable<Diagnostic> diagnostics) | |||
{ | |||
Diagnostic myDiagnostic = null; | |||
List<Diagnostic> myDiagnostics = new List<Diagnostic>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: outputDiagnostics
or resultDiagnostics
maybe? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1470,7 +1470,7 @@ private ImmutableArray<string> BuildSearchPaths(string sdkDirectoryOpt, List<str | |||
|
|||
public static IEnumerable<string> ParseConditionalCompilationSymbols(string value, out IEnumerable<Diagnostic> diagnostics) | |||
{ | |||
Diagnostic myDiagnostic = null; | |||
List<Diagnostic> myDiagnostics = new List<Diagnostic>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List myDiagnostics = new List(); [](start = 12, length = 56)
Can we use a DiagnosticBag instead (probably from the pool)? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or an ArrayBuilder? We usually don't use List of T.
In reply to: 100169189 [](ancestors = 100169189)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like we are validating pre-processor symbols in parse options. I thought the plan was to move validation elsewhere.
@@ -8101,6 +8101,31 @@ End Module | |||
Assert.Equal($"error BC2012: can't open '{sourceLinkPath}' for writing: Fake IOException{Environment.NewLine}", outWriter.ToString()) | |||
End Sub | |||
|
|||
<WorkItem(15900, "https://github.com/dotnet/roslyn/issues/15900")> | |||
<Fact> | |||
Public Sub CompilingCodeWithInvalidPreProcessorSymbolsShouldErrorOut() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CompilingCodeWithInvalidPreProcessorSymbolsShouldErrorOut [](start = 19, length = 57)
Could you include how the errors look like as text, as comments perhaps? #Resolved
|
Based on discussion with AlekseyTs, there are surfaces that are not covered by this change. |
Fixes #15900 in both C# and VB, by removing validation from ParseOptions, and adding tests to make sure that it doesn't throw exceptions.
Fixes #16913 only in C#, as VB parses input as tokens (not by splitting input), and has special back-compat reasons for keeping this behavior.
Note to self: inspect breaking API change.