Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit e8e2a06

Browse files
committed
Fix some analyzer violations.
1 parent f0c2199 commit e8e2a06

File tree

15 files changed

+30
-54
lines changed

15 files changed

+30
-54
lines changed

src/benchmarks/CelerityBenchmarkConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public CelerityBenchmarkConfig(bool test, string? filter)
1212
_ = AddValidator(JitOptimizationsValidator.FailOnError);
1313

1414
if (filter != null)
15-
_ = AddFilter(new GlobFilter(new[] { filter }));
15+
_ = AddFilter(new GlobFilter([filter]));
1616

1717
_ = WithOptions(ConfigOptions.JoinSummary | ConfigOptions.StopOnFirstError)
1818
.WithArtifactsPath(Path.Join(Path.GetDirectoryName(Environment.ProcessPath!)!, "artifacts"))

src/common/EventHandlerList`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public readonly void Raise<TState>(TState state, Action<T, TState> raiser)
4949
}
5050
catch (Exception ex)
5151
{
52-
(exceptions ??= new()).Add(ex);
52+
(exceptions ??= []).Add(ex);
5353
}
5454
}
5555

src/generators/Semantics/SemanticTreeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2828

2929
var baseName = Path.GetFileName(file.Path);
3030

31-
foreach (var type in root.Types ?? Array.Empty<SemanticTreeType>())
31+
foreach (var type in root.Types ?? [])
3232
GenerateType(ctx, Path.ChangeExtension(baseName, $"{type.Name}Semantics.g.cs"), type);
3333
});
3434
}
@@ -72,7 +72,7 @@ private static void GenerateType(SourceProductionContext context, string name, S
7272
writer.WriteLine();
7373
}
7474

75-
var props = type.Properties ?? Array.Empty<SemanticTreeProperty>();
75+
var props = type.Properties ?? [];
7676

7777
foreach (var prop in props)
7878
{

src/generators/Syntax/SyntaxTreeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2828

2929
var baseName = Path.GetFileName(file.Path);
3030

31-
foreach (var type in root.Types ?? Array.Empty<SyntaxTreeType>())
31+
foreach (var type in root.Types ?? [])
3232
GenerateType(ctx, Path.ChangeExtension(baseName, $"{type.Name}Syntax.g.cs"), type);
3333
});
3434
}
@@ -65,7 +65,7 @@ private static void GenerateType(SourceProductionContext context, string name, S
6565
writer.WriteLine();
6666
}
6767

68-
var props = type.Properties ?? Array.Empty<SyntaxTreeProperty>();
68+
var props = type.Properties ?? [];
6969

7070
foreach (var prop in props)
7171
{

src/language/core/Quality/LintPass.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ namespace Vezel.Celerity.Language.Quality;
66
public abstract class LintPass
77
{
88
public static ImmutableArray<LintPass> DefaultPasses { get; } =
9-
ImmutableArray.Create<LintPass>(
9+
[
1010
TestWithoutAssertPass.Instance,
1111
UndocumentedPublicSymbolPass.Instance,
1212
UnreachableCodePass.Instance,
1313
UnusedLocalSymbolPass.Instance,
14-
UppercaseBaseIndicatorPass.Instance);
14+
UppercaseBaseIndicatorPass.Instance
15+
];
1516

1617
public DiagnosticCode Code { get; }
1718

src/language/core/Semantics/Binding/LambdaScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class LambdaScope : FunctionScope, IScope<LambdaScope>
77
public ImmutableArray<ThisExpressionSemantics>.Builder ThisExpressions { get; } =
88
ImmutableArray.CreateBuilder<ThisExpressionSemantics>(0);
99

10-
private readonly Dictionary<Symbol, UpvalueSymbol> _upvalues = new();
10+
private readonly Dictionary<Symbol, UpvalueSymbol> _upvalues = [];
1111

1212
private int _upvalueSlot;
1313

src/language/core/Semantics/Binding/LocalSymbol.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ public abstract class LocalSymbol : Symbol
1414

1515
public override sealed ImmutableArray<AssignmentExpressionSemantics> Assignments => _assignments;
1616

17-
private ImmutableArray<SemanticNode> _bindings = ImmutableArray<SemanticNode>.Empty;
17+
private ImmutableArray<SemanticNode> _bindings = [];
1818

19-
private ImmutableArray<IdentifierExpressionSemantics> _references =
20-
ImmutableArray<IdentifierExpressionSemantics>.Empty;
19+
private ImmutableArray<IdentifierExpressionSemantics> _references = [];
2120

22-
private ImmutableArray<AssignmentExpressionSemantics> _assignments =
23-
ImmutableArray<AssignmentExpressionSemantics>.Empty;
21+
private ImmutableArray<AssignmentExpressionSemantics> _assignments = [];
2422

2523
private protected LocalSymbol(string name)
2624
{

src/language/core/Semantics/Binding/Scope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ internal class Scope : IScope<Scope>
66
{
77
public Scope? Parent { get; }
88

9-
private readonly Dictionary<string, Symbol> _symbols = new();
9+
private readonly Dictionary<string, Symbol> _symbols = [];
1010

1111
protected internal Scope(Scope? parent)
1212
{

src/language/core/Semantics/LanguageAnalyzer.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ public void Dispose()
3636

3737
private readonly ImmutableArray<Diagnostic>.Builder _diagnostics;
3838

39-
private readonly Dictionary<string, (List<UseDeclarationSemantics> Declarations, ModulePath? Path)> _uses =
40-
new();
39+
private readonly Dictionary<string, (List<UseDeclarationSemantics> Declarations, ModulePath? Path)> _uses = [];
4140

42-
private readonly List<IdentifierExpressionSemantics> _identifiers = new();
41+
private readonly List<IdentifierExpressionSemantics> _identifiers = [];
4342

44-
private readonly HashSet<Symbol> _duplicates = new();
43+
private readonly HashSet<Symbol> _duplicates = [];
4544

4645
private Scope _scope = new(null);
4746

@@ -183,7 +182,7 @@ private SemanticNodeList<TSemantics, TSyntax> ConvertList<TSyntax, TSemantics>(
183182
where TSemantics : SemanticNode
184183
{
185184
if (syntax.Count == 0)
186-
return new(syntax, ImmutableArray<TSemantics>.Empty);
185+
return new(syntax, []);
187186

188187
var builder = Builder<TSemantics>(syntax.Count);
189188

@@ -251,7 +250,7 @@ value is ReadOnlyMemory<byte> utf8 &&
251250
$"Value for standard attribute '{name}' must be a {valueMsg}");
252251

253252
if (!allowMultiple)
254-
(CollectionsMarshal.GetValueRefOrAddDefault(grouped, name, out _) ??= new()).Add(attr);
253+
(CollectionsMarshal.GetValueRefOrAddDefault(grouped, name, out _) ??= []).Add(attr);
255254
}
256255

257256
foreach (var (name, list) in grouped.OrderBy(static kvp => kvp.Key))
@@ -273,7 +272,7 @@ private SeparatedSemanticNodeList<TSemantics, TSyntax> ConvertList<TSyntax, TSem
273272
var elements = syntax.Elements;
274273

275274
if (elements.Length == 0)
276-
return new(syntax, ImmutableArray<TSemantics>.Empty);
275+
return new(syntax, []);
277276

278277
var builder = Builder<TSemantics>(elements.Length);
279278

@@ -298,7 +297,7 @@ private void CheckDuplicateFields<TSemantics, TSyntax>(
298297

299298
foreach (var field in fields)
300299
if (selector(field) is { IsMissing: false } name)
301-
(CollectionsMarshal.GetValueRefOrAddDefault(map, name.Text, out _) ??= new()).Add(name.Span);
300+
(CollectionsMarshal.GetValueRefOrAddDefault(map, name.Text, out _) ??= []).Add(name.Span);
302301

303302
foreach (var (name, spans) in map)
304303
if (spans.Count != 1)
@@ -412,7 +411,7 @@ public override UseDeclarationSemantics VisitUseDeclaration(UseDeclarationSyntax
412411
ref var entry = ref CollectionsMarshal.GetValueRefOrAddDefault(_uses, name.Text, out var exists);
413412

414413
if (!exists)
415-
entry = (new(), path);
414+
entry = ([], path);
416415

417416
entry.Declarations.Add(sema);
418417
}
@@ -1140,9 +1139,7 @@ public override CallExpressionSemantics VisitCallExpression(CallExpressionSyntax
11401139
{
11411140
var subject = VisitExpression(node.Subject);
11421141
var args = ConvertList(node.ArgumentList.Arguments, static (@this, arg) => @this.VisitExpression(arg));
1143-
var defers = node.QuestionToken != null
1144-
? _scope.CollectDefers(null)
1145-
: ImmutableArray<DeferStatementSemantics>.Empty;
1142+
var defers = node.QuestionToken != null ? _scope.CollectDefers(null) : [];
11461143

11471144
var sema = new CallExpressionSemantics(node, subject, args, defers);
11481145

src/language/core/Syntax/LanguageLexer.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal sealed class LanguageLexer
2222

2323
private readonly StringBuilder _token = new();
2424

25-
private readonly List<char> _string = new();
25+
private readonly List<char> _string = [];
2626

2727
private readonly StringBuilder _closingIndentation = new();
2828

@@ -81,14 +81,7 @@ private void Error(int position, DiagnosticCode code, string message)
8181

8282
private void Error(int position, int length, DiagnosticCode code, string message)
8383
{
84-
_diagnostics.Add(
85-
tree => new(
86-
tree,
87-
new(position, length),
88-
DiagnosticSeverity.Error,
89-
code,
90-
message,
91-
ImmutableArray<DiagnosticNote>.Empty));
84+
_diagnostics.Add(tree => new(tree, new(position, length), DiagnosticSeverity.Error, code, message, []));
9285

9386
_errors = true;
9487
}

0 commit comments

Comments
 (0)