Skip to content

Commit f9e63fb

Browse files
committed
Check parse options in UnsupportedCSharpLanguageVersionAnalyzer
1 parent 74fc2aa commit f9e63fb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Immutable;
77
using System.Linq;
88
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.CSharp;
910
using Microsoft.CodeAnalysis.Diagnostics;
1011
using static CommunityToolkit.Mvvm.SourceGenerators.Diagnostics.DiagnosticDescriptors;
1112

@@ -50,6 +51,12 @@ public override void Initialize(AnalysisContext context)
5051
return;
5152
}
5253

54+
// Check that the language version is not high enough, otherwise no diagnostic should be produced
55+
if (context.Symbol.DeclaringSyntaxReferences.FirstOrDefault() is not { SyntaxTree.Options: CSharpParseOptions { LanguageVersion: < LanguageVersion.CSharp8 } })
56+
{
57+
return;
58+
}
59+
5360
ImmutableArray<AttributeData> attributes = context.Symbol.GetAttributes();
5461

5562
// If the symbol has no attributes, there's nothing left to do

0 commit comments

Comments
 (0)