提交 4ced964a 编写于 作者: J Jared Parsons

Fix NRE in command line parsing

The command line parser was inconsistent in how it set the
sourceFilesSpecified boolean flag.  In one place it tracked whether the
source files collection was non empty and in another it tracked whether
or not we had attempted to parse an argument as a source file.  This
disconnect lead to a NRE when there was an invalid source file and the
command line tried to calculate the output name for a library project.
Changed the compiler to consistently treat it as tracking whether or not
a valid source file was specified.
上级 abd493f0
......@@ -140,7 +140,10 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
if (!TryParseOption(arg, out name, out value))
{
sourceFiles.AddRange(ParseFileArgument(arg, baseDirectory, diagnostics));
sourceFilesSpecified = true;
if (sourceFiles.Count > 0)
{
sourceFilesSpecified = true;
}
continue;
}
......@@ -1131,7 +1134,6 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
};
}
private static void ParseAndResolveReferencePaths(string switchName, string switchValue, string baseDirectory, List<string> builder, MessageID origin, List<Diagnostic> diagnostics)
{
if (string.IsNullOrEmpty(switchValue))
......
......@@ -324,6 +324,16 @@ public void SourceFiles_Patterns2()
Assert.Equal(4, resolvedSourceFiles.Length);
}
[ConditionalFact(typeof(WindowsOnly))]
public void SourceFile_BadPath()
{
var args = DefaultParse(new[] { @"e:c:\test\test.cs", "/t:library" }, _baseDirectory);
Assert.Equal(3, args.Errors.Length);
Assert.Equal((int)ErrorCode.FTL_InputFileNameTooLong, args.Errors[0].Code);
Assert.Equal((int)ErrorCode.WRN_NoSources, args.Errors[1].Code);
Assert.Equal((int)ErrorCode.ERR_OutputNeedsName, args.Errors[2].Code);
}
private void CreateFile(TempDirectory folder, string file)
{
var f = folder.CreateFile(file);
......
......@@ -7241,6 +7241,13 @@ End Class
CleanupAllGeneratedFiles(file.Path)
End Sub
<ConditionalFact(GetType(WindowsOnly))>
Public Sub SourceFile_BadPath()
Dim args = DefaultParse({"e:c:\test\test.cs", "/t:library"}, _baseDirectory)
args.Errors.Verify(Diagnostic(ERRID.FTL_InputFileNameTooLong).WithArguments("e:c:\test\test.cs").WithLocation(1, 1))
End Sub
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册