Skip to content

fix: check StateDiagram inheritance semantically, not syntactically - #265

Merged
Bastani merged 5 commits into
chickensoft-games:mainfrom
spirifoxy:fix/state-diagram-indirect-base-type
Oct 5, 2026
Merged

Bastani merged 5 commits into
chickensoft-games:mainfrom
spirifoxy:fix/state-diagram-indirect-base-type

Conversation

@spirifoxy

Copy link
Copy Markdown
Contributor

[StateDiagram] is silently ignored when the attributed record's base type is not literally named LogicBlockState and that base is not declared in the same file. The generator falls through to the unrelated IsLogicBlockCandidate path and writes a stub diagram containing only the initial state.

Reproduction

// SharedBase.cs
public abstract record SharedBase : LogicBlockState;

// MyLogic.cs
public partial class MyLogic : LogicBlock {
  [StateDiagram]
  public abstract partial record MyState : SharedBase; 
  ...
}

Gives

@startuml MyLogic
state MyLogic {
  state Dark
}

[*] --> Dark
@enduml

Changing : SharedBase to : LogicBlockState produces the correct diagram with every state and transition.

Fix

Move the inheritance check from the syntax predicate into the semantic transform .

  • IsStateDiagramCandidate now only checks for the attribute.
  • DiscoverStateGraph verifies inheritance via CodeService.GetAllBaseTypes, the same helper it already uses a few lines further down, and returns null if the type is not a logic block state.

@wlsnmrk
wlsnmrk requested a review from Bastani October 1, 2026 19:19
@wlsnmrk wlsnmrk added bug Something isn't working diagrams labels Oct 1, 2026

@Bastani Bastani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your submission, I made a few comments about the changes, looks good otherwise!

.Any(attr => attr.Name.ToString() == Constants.LOGIC_BLOCK_ATTRIBUTE_NAME);
}

private static bool InheritsFromLogicBlockState(INamedTypeSymbol symbol) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix shows a bigger problem with CodeService.InheritsFromByName, it only checks within the same file. There's a similar bug with if you were to make a base LogicBlock.

I think the CodeService.InheritsFromByName should probably be removed to discourage people from using it.

If you're open to fixing that in this PR, that would be great, otherwise I can open another after this is merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, fixing that also turned up two more partial-class bugs

  • a Start call in a second file silently dropped the diagram
  • every partial calling Start would have emitted its own diagram

Both are fixed

Comment thread Chickensoft.LogicBlocks.DiagramGenerator/src/DiagramGenerator.cs Outdated
@spirifoxy

Copy link
Copy Markdown
Contributor Author

Thank you for your submission, I made a few comments about the changes, looks good otherwise!

Thanks for the review! All three are addressed

@Bastani
Bastani merged commit bd63ea6 into chickensoft-games:main Oct 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working diagrams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants