Skip to content

Commit 85fca91

Browse files
committed
Fixed RequiredUsageAnalyzer not taking into account plain properties marked as Required.
1 parent 10d41b8 commit 85fca91

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/reactive/Reactive.Compiler/Features/Required/RequiredUsageAnalyzer.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@ private static void AnalyzeInitializer(SyntaxNodeAnalysisContext context) {
2424
var assigned = node.Initializer.ChildNodes()
2525
.OfType<AssignmentExpressionSyntax>()
2626
.Where(x => x.Left is IdentifierNameSyntax)
27-
.Select(x => semanticModel.GetSymbolInfo(x.Left).Symbol);
27+
.Select(x => semanticModel.GetSymbolInfo(x.Left).Symbol)
28+
.ToArray();
2829

30+
// Properties set by another properties with SetsRequired attributes
2931
var setNames = assigned
3032
.Select(x => x!.GetAttribute<SetsRequiredAttribute>(semanticModel))
3133
.OfType<AttributeData>()
3234
.Select(x => x.GetNamedArgument(nameof(SetsRequiredAttribute.Names)))
3335
.SelectMany(x => x?.Values.Select(y => y.Value))
3436
.OfType<string>();
37+
38+
// Required properties set directly
39+
var reqNames = assigned
40+
.Where(x => x!.GetAttribute<RequiredAttribute>(semanticModel) != null)
41+
.Select(x => x!.Name);
3542

3643
// If property is assigned we remove it from the required list
37-
foreach (var name in setNames) {
44+
foreach (var name in setNames.Concat(reqNames)) {
3845
required.Remove(name);
3946
}
4047
}

0 commit comments

Comments
 (0)