Exemplo n.º 1
0
        private static bool OutputDiagnostics(Project project, FixedList <Diagnostic> diagnostics, object consoleLock)
        {
            if (!diagnostics.Any())
            {
                return(false);
            }
            lock (consoleLock)
            {
                Console.WriteLine($@"Build FAILED {project.Name} ({project.Path})");
                foreach (var group in diagnostics.GroupBy(d => d.File))
                {
                    var fileDiagnostics = @group.ToList();
                    foreach (var diagnostic in fileDiagnostics.Take(10))
                    {
                        Console.WriteLine(
                            $@"{diagnostic.File.Reference}:{diagnostic.StartPosition.Line}:{diagnostic.StartPosition.Column} {diagnostic.Level} {diagnostic.ErrorCode}");
                        Console.WriteLine(@"    " + diagnostic.Message);
                    }

                    if (fileDiagnostics.Count > 10)
                    {
                        Console.WriteLine($"{@group.Key.Reference}");
                        Console.WriteLine(
                            $"    {fileDiagnostics.Skip(10).Count(d => d.Level >= DiagnosticLevel.CompilationError)} more errors not shown.");
                        Console.WriteLine(
                            $"    {fileDiagnostics.Skip(10).Count(d => d.Level == DiagnosticLevel.Warning)} more warnings not shown.");
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private List <Diagnostic> CheckErrorsExpected(
            TestCase testCase,
            CodeFile codeFile,
            string code,
            FixedList <Diagnostic> diagnostics)
        {
            // Check for compiler errors
            var expectCompileErrors       = ExpectCompileErrors(code);
            var expectedCompileErrorLines = ExpectedCompileErrorLines(codeFile, code);

            if (diagnostics.Any())
            {
                testOutput.WriteLine("Compiler Errors:");
                foreach (var diagnostic in diagnostics)
                {
                    testOutput.WriteLine(
                        $"{testCase.RelativeCodePath}:{diagnostic.StartPosition.Line}:{diagnostic.StartPosition.Column} {diagnostic.Level} {diagnostic.ErrorCode}");
                    testOutput.WriteLine(diagnostic.Message);
                }

                testOutput.WriteLine("");
            }

            var errorDiagnostics = diagnostics
                                   .Where(d => d.Level >= DiagnosticLevel.CompilationError).ToList();

            if (expectedCompileErrorLines.Any())
            {
                foreach (var expectedCompileErrorLine in expectedCompileErrorLines)
                {
                    // Assert a single error on the given line
                    var errorsOnLine = errorDiagnostics.Count(e =>
                                                              e.StartPosition.Line == expectedCompileErrorLine);
                    Assert.True(errorsOnLine == 1,
                                $"Expected one error on line {expectedCompileErrorLine}, found {errorsOnLine}");
                }
            }

            if (expectCompileErrors)
            {
                Assert.True(errorDiagnostics.Any(), "Expected compilation errors and there were none");
            }
            else
            {
                foreach (var error in errorDiagnostics)
                {
                    var errorLine = error.StartPosition.Line;
                    if (expectedCompileErrorLines.All(line => line != errorLine))
                    {
                        Assert.True(false, $"Unexpected error on line {error.StartPosition.Line}");
                    }
                }
            }

            return(errorDiagnostics);
        }
        private LexicalScope BuildUsingDirectivesScope(
            LexicalScope containingScope,
            FixedList <UsingDirectiveSyntax> usingDirectives)
        {
            if (!usingDirectives.Any())
            {
                return(containingScope);
            }

            var importedSymbols = usingDirectives
                                  .SelectMany(d => allSymbols.Where(s => s.FullName.HasQualifier(d.Name)));

            return(new NestedScope(containingScope, importedSymbols, Enumerable.Empty <ISymbol>()));
        }
Exemplo n.º 4
0
        private LexicalScope BuildUsingDirectivesScope(
            FixedList <IUsingDirectiveSyntax> usingDirectives,
            LexicalScope containingScope)
        {
            if (!usingDirectives.Any())
            {
                return(containingScope);
            }

            var importedSymbols = new Dictionary <TypeName, HashSet <IPromise <Symbol> > >();

            foreach (var usingDirective in usingDirectives)
            {
                if (!namespaces.TryGetValue(usingDirective.Name, out var ns))
                {
                    // TODO diagnostics.Add(NameBindingError.UsingNonExistentNamespace(file, usingDirective.Span, usingDirective.Name));
                    continue;
                }

                foreach (var(name, additionalSymbols) in ns.Symbols)
                {
                    if (importedSymbols.TryGetValue(name, out var symbols))
                    {
                        symbols.AddRange(additionalSymbols);
                    }
                    else
                    {
                        importedSymbols.Add(name, additionalSymbols.ToHashSet());
                    }
                }
            }

            var symbolsInScope = importedSymbols.ToFixedDictionary(e => e.Key, e => e.Value.ToFixedSet());

            return(NestedScope.Create(containingScope, symbolsInScope));
        }