Skip to content

Commit

Permalink
Fix some analyzer diagnostics.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Feb 14, 2024
1 parent 56b938f commit 091fa94
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/driver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public static async Task<int> Main(string[] args)
return await parser
.ParseArguments(
args,
typeof(ThisAssembly)
[.. typeof(ThisAssembly)
.Assembly
.DefinedTypes
.Where(static type => type.GetCustomAttribute<VerbAttribute>() != null)
.ToArray())
.Where(static type => type.GetCustomAttribute<VerbAttribute>() != null)])
.MapResult(
verb => Unsafe.As<Verb>(verb).RunWithHandlerAsync(cts.Token),
static _ => ValueTask.FromResult(1));
Expand Down
2 changes: 1 addition & 1 deletion src/driver/Verbs/CheckVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override async ValueTask<int> RunAsync(CancellationToken cancellationT

try
{
diags = (await doc.GetDiagnosticsAsync(cancellationToken)).ToArray();
diags = [.. await doc.GetDiagnosticsAsync(cancellationToken)];
}
catch (PathTooLongException)
{
Expand Down
4 changes: 2 additions & 2 deletions src/language/core/Semantics/Tree/SemanticNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private protected SemanticNode(SyntaxNode syntax)

public IEnumerable<SemanticNode> Ancestors()
{
return Parent?.AncestorsAndSelf() ?? Array.Empty<SemanticNode>();
return Parent?.AncestorsAndSelf() ?? [];
}

public IEnumerable<SemanticNode> AncestorsAndSelf()
Expand All @@ -50,7 +50,7 @@ public IEnumerable<SemanticNode> Siblings()

public IEnumerable<SemanticNode> SiblingsAndSelf()
{
foreach (var sibling in Parent?.Children() ?? Array.Empty<SemanticNode>())
foreach (var sibling in Parent?.Children() ?? [])
yield return sibling;
}

Expand Down
4 changes: 2 additions & 2 deletions src/language/core/Syntax/Tree/SyntaxItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal void SetParent(object parent)

public IEnumerable<SyntaxItem> Ancestors()
{
return Parent?.AncestorsAndSelf() ?? Array.Empty<SyntaxItem>();
return Parent?.AncestorsAndSelf() ?? [];
}

public IEnumerable<SyntaxItem> AncestorsAndSelf()
Expand All @@ -51,7 +51,7 @@ public IEnumerable<SyntaxItem> Siblings()

public IEnumerable<SyntaxItem> SiblingsAndSelf()
{
foreach (var sibling in Parent?.Children() ?? Array.Empty<SyntaxItem>())
foreach (var sibling in Parent?.Children() ?? [])
yield return sibling;
}

Expand Down
4 changes: 2 additions & 2 deletions src/language/core/Syntax/Tree/SyntaxTrivia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal SyntaxTrivia(int position, SyntaxTriviaKind kind, string text)

public override IEnumerable<SyntaxTerminal> Children()
{
return Array.Empty<SyntaxTerminal>();
return [];
}

public new IEnumerable<SyntaxTrivia> ChildrenAndSelf()
Expand All @@ -47,7 +47,7 @@ public override IEnumerable<SyntaxTerminal> Children()

public override IEnumerable<SyntaxTerminal> Descendants()
{
return Array.Empty<SyntaxTerminal>();
return [];
}

public new IEnumerable<SyntaxTrivia> DescendantsAndSelf()
Expand Down
7 changes: 3 additions & 4 deletions src/language/tooling/Workspaces/WorkspaceDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal WorkspaceDocument(Workspace workspace, WorkspaceDocumentAttributes attr
_state = path;

if (attributes.HasFlag(WorkspaceDocumentAttributes.SuppressDiagnostics))
_diagnostics = Array.Empty<Diagnostic>();
_diagnostics = [];
}

public ValueTask<SourceText> GetTextAsync(CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -126,13 +126,12 @@ public async ValueTask<IEnumerable<Diagnostic>> GetDiagnosticsAsync(Cancellation
{
var semantics = await GetSemanticsAsync(cancellationToken).ConfigureAwait(false);

_diagnostics = semantics
_diagnostics = [.. semantics
.Syntax
.Diagnostics
.Concat(semantics.Diagnostics)
.Where(static diag => diag.Severity != DiagnosticSeverity.None)
.OrderBy(static diag => diag.Span)
.ToArray();
.OrderBy(static diag => diag.Span)];
}

return _diagnostics;
Expand Down
7 changes: 1 addition & 6 deletions src/runtime/core/Metadata/RuntimeFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ internal RuntimeFunction(RuntimeModule module, FunctionDeclarationSemantics func
}

internal RuntimeFunction(RuntimeModule module, LambdaExpressionSemantics function)
: this(
module,
isPublic: false,
${module.AllocateLambdaId()}",
Array.Empty<AttributeSemantics>(),
function.Parameters)
: this(module, isPublic: false, ${module.AllocateLambdaId()}", attributes: [], function.Parameters)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/DriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private sealed class DirectoryBuilder

public DirectoryBuilder()
{
Files = ImmutableArray<(string, string)>.Empty;
Files = [];
}

private DirectoryBuilder(ImmutableArray<(string Name, string Contents)> files)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/QualityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private static Task TestAsync(
var syntax = SyntaxTree.Parse(
new StringSourceText($"{name}.cel", contents), SyntaxMode.Module, discardText: true);
var semantics = SemanticTree.Analyze(
syntax, context: null, new LintDiagnosticAnalyzer(new[] { pass }, LintConfiguration.Default));
syntax, context: null, new LintDiagnosticAnalyzer([pass], LintConfiguration.Default));

return VerifyDiagnosticsAsync(
syntax.Diagnostics.Concat(semantics.Diagnostics).OrderBy(static diag => diag.Span), file, name);
Expand Down

0 comments on commit 091fa94

Please sign in to comment.