T302
type contains itself
Severity Error
A record type contains a field of its own type, directly or through other records. Records are stored by value, so such a type would have infinite size.
Break the cycle: store an index or an id that refers to the other record, and keep the records in an array or map.
Failing example
script "Level chain"
data chart = subscribe(data.ohlcv)
type Level {
price: float
next: Level
}
state levels = map<int, float>(100)
on chart.close {
levels[chart.index] = chart.close ?? 0.0
}Fixed example
script "Level chain"
data chart = subscribe(data.ohlcv)
type Level {
price: float
nextIndex: int
}
state levels = map<int, float>(100)
on chart.close {
levels[chart.index] = chart.close ?? 0.0
}