File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
ExternalProjects/BizHawk.Analyzer Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
1
namespace BizHawk . Analyzers ;
2
2
3
+ using System ;
3
4
using System . Collections . Immutable ;
4
5
using System . Linq ;
5
6
@@ -42,8 +43,13 @@ public override void Initialize(AnalysisContext context)
42
43
var operation = ( IInvocationOperation ) oac . Operation ;
43
44
var calledSym = operation . TargetMethod . ConstructedFrom ;
44
45
if ( ! ( firstOrDefaultWithPredSym ! . Matches ( calledSym ) || firstOrDefaultNoPredSym ! . Matches ( calledSym ) ) ) return ;
45
- var receiverExprType = ( INamedTypeSymbol ) operation . SemanticModel ! . GetTypeInfo ( ( CSharpSyntaxNode ) operation . Arguments [ 0 ] . Syntax ) ! . ConvertedType ! ;
46
- if ( receiverExprType . TypeArguments [ 0 ] . IsValueType ) oac . ReportDiagnostic ( Diagnostic . Create ( DiagUseFirstOrNull , operation . Syntax . GetLocation ( ) ) ) ;
46
+ var receiverExprType = operation . SemanticModel ! . GetTypeInfo ( ( CSharpSyntaxNode ) operation . Arguments [ 0 ] . Syntax ) . ConvertedType ! ;
47
+ var collectionElemType = receiverExprType switch {
48
+ INamedTypeSymbol nts => nts . TypeArguments [ 0 ] ,
49
+ IArrayTypeSymbol ats => ats . ElementType ,
50
+ _ => throw new InvalidOperationException ( $ "receiver parameter's effective type was of an unexpected kind (neither class/struct nor array): { receiverExprType } ")
51
+ } ;
52
+ if ( collectionElemType . IsValueType ) oac . ReportDiagnostic ( Diagnostic . Create ( DiagUseFirstOrNull , operation . Syntax . GetLocation ( ) ) ) ;
47
53
} ,
48
54
OperationKind . Invocation ) ;
49
55
} ) ;
You can’t perform that action at this time.
0 commit comments