diff --git a/src/D2L.CodeStyle.Analyzers/Language/RequireNamedArgumentsAnalyzer.cs b/src/D2L.CodeStyle.Analyzers/Language/RequireNamedArgumentsAnalyzer.cs index fababa9d..e9db6766 100644 --- a/src/D2L.CodeStyle.Analyzers/Language/RequireNamedArgumentsAnalyzer.cs +++ b/src/D2L.CodeStyle.Analyzers/Language/RequireNamedArgumentsAnalyzer.cs @@ -99,7 +99,7 @@ private static void AnalyzeInvocation( // Don't complain about expression trees, since they aren't allowed // to have named arguments - if( IsExpressionTree( lambdaExpresssionSymbol, ctx.Operation.SemanticModel!, ctx.Operation ) ) { + if( IsExpressionTree( lambdaExpresssionSymbol, ctx.Operation ) ) { return; } @@ -172,32 +172,27 @@ private static void AnalyzeInvocation( private static bool IsExpressionTree( INamedTypeSymbol? expressionType, - SemanticModel model, IOperation operation ) { if( expressionType == null || expressionType.Kind == SymbolKind.ErrorType ) { return false; } - // the current call could be nested inside an expression tree, so - // check every call we are nested inside - foreach( var syntax in operation.Syntax.AncestorsAndSelf() ) { - if( !( syntax is InvocationExpressionSyntax || syntax is ObjectCreationExpressionSyntax ) ) { - continue; - } + IOperation? current = operation; + for( ; ; ) { + current = current?.Parent; - if( syntax.Parent is null ) { + if( current is null ) { + break; + } + + if( current is not IConversionOperation conversion ) { continue; - } - - var implicitType = model.GetTypeInfo( syntax.Parent ).ConvertedType; - if( implicitType != null && implicitType.Kind != SymbolKind.ErrorType ) { - - var baseExprType = implicitType.BaseType; - if( expressionType.OriginalDefinition.Equals( baseExprType, SymbolEqualityComparer.Default ) ) { - return true; - } - } + } + + if( SymbolEqualityComparer.Default.Equals( expressionType, conversion.Type?.BaseType ) ) { + return true; + } } return false;