diff --git a/Chickensoft.LogicBlocks.Analyzers/src/LogicBlockAttributeAnalyzer.cs b/Chickensoft.LogicBlocks.Analyzers/src/LogicBlockAttributeAnalyzer.cs index b5a60b2..20496eb 100644 --- a/Chickensoft.LogicBlocks.Analyzers/src/LogicBlockAttributeAnalyzer.cs +++ b/Chickensoft.LogicBlocks.Analyzers/src/LogicBlockAttributeAnalyzer.cs @@ -32,16 +32,30 @@ private void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) { var classDeclaration = (ClassDeclarationSyntax)context.Node; if ( - !( - classDeclaration.BaseList?.Types.FirstOrDefault()?.Type - is GenericNameSyntax genericName && - genericName.Identifier.ValueText.EndsWith("LogicBlock") - ) + classDeclaration.BaseList?.Types.FirstOrDefault()?.Type is not GenericNameSyntax baseLogicBlock || + !baseLogicBlock.Identifier.ValueText.EndsWith("LogicBlock") ) { // Only analyze types that appear to be logic blocks. return; } + // We can't apply the LogicBlock attribute to generic LogicBlock types + // if one of the generics is the state type + if ( + classDeclaration.TypeParameterList is not null + && classDeclaration.TypeParameterList.Parameters.Count > 0 + && classDeclaration.TypeParameterList.Parameters.Any( + parameter => + baseLogicBlock.TypeArgumentList.Arguments.Any( + argument => + argument is IdentifierNameSyntax identifierArg + && identifierArg.Identifier.ValueText == parameter.Identifier.ValueText + ) + ) + ) { + return; + } + var attributes = classDeclaration.AttributeLists.SelectMany( list => list.Attributes ).Where(