Skip to content

03: Circular Dependencies / Out-of-Order Definitions (The "Topological Sort" Limitation) #145

@dschwartznyc

Description

@dschwartznyc

Bug Report

Problem Description:

The generator uses a Directed Acyclic Graph (DAG) to order definitions in _bundle.py. However, the current implementation only includes edges for inheritance (SuperTypes). It ignores Attribute types, leading to out-of-order definitions. Furthermore, Rosetta allows recursive/circular types (A has B, B has A), which a DAG cannot resolve by design. Inheritance-based cycles are particularly fatal as base classes must be defined before children.

Steps to Reproduce:

  1. Define two types that refer to each other as attributes.
  2. Define a child type that inherits from a parent, while the parent refers to the child.
  3. Import the generated classes.
type CircularA:
    b CircularB (1..1)

type CircularB:
    a CircularA (1..1)

Test Cases:

type Parent:
    child Child (0..1)

type Child extends Parent:
    val int (1..1)

Test Cases:

Expected Result:

Definitions should be correctly ordered or forward-referenced using String type hints to allow successful import of the bundle.

Actual Result:

NameError: name '...Parent' is not defined occurs because the generator emitted Child before Parent.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions