Skip to content

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

Open
spirifoxy wants to merge 1 commit into
chickensoft-games:mainfrom
spirifoxy:fix/state-diagram-indirect-base-type
Open

fix: check StateDiagram inheritance semantically, not syntactically#265
spirifoxy wants to merge 1 commit into
chickensoft-games:mainfrom
spirifoxy:fix/state-diagram-indirect-base-type

Conversation

@spirifoxy

Copy link
Copy Markdown

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant