FlowscopeDocs

T306

record literal has wrong fields

Severity Error

A record literal Name { ... } must set every field of the type exactly once, with a value of the field’s type. The literal here omits a field, names a field that does not exist, repeats one, or passes a value of the wrong type.

Match the declared field list. Fields cannot have defaults, so nullable fields still need an explicit null.

Failing example

Flowscope Script
script "Print log"
data tape = subscribe(data.trades, minNotional: 500_000.0)
type Print {
  price: float
  usd: float
  buy: bool
}
state last: Print? = null
on tape.trade(tr) {
  let prev = last
  if prev != null && prev.buy != tr.isBuy {
    log.info(str.format("side flip at {0}", tr.price))
  }
  last = Print { price: tr.price, usd: tr.notional }
}

Fixed example

Flowscope Script
script "Print log"
data tape = subscribe(data.trades, minNotional: 500_000.0)
type Print {
  price: float
  usd: float
  buy: bool
}
state last: Print? = null
on tape.trade(tr) {
  let prev = last
  if prev != null && prev.buy != tr.isBuy {
    log.info(str.format("side flip at {0}", tr.price))
  }
  last = Print { price: tr.price, usd: tr.notional, buy: tr.isBuy }
}