Duolith docs

Errors while checking a page

E0178 Behaviour value copied once

Message This copies object.name once, and the copy stops following it

Words in italics are filled in when the compiler reports it, such as the element's name or the list of known ones.

Why

A behaviour's result reads each returned state and derived value each time it is used, so a script may keep it whole (let cal = calendar(...)), name it again (let other = cal), pass it to a component or a function, and read cal.month or cal["month"] anywhere a value is shown or computed later (decision 0152). Code at the top of a script, or of a behaviour's body, runs once: there, outside any function, derived value, effect, markup expression or behaviour input, reading a returned state or derived value from a whole result reads it once and never again. So the build refuses let m = cal.month, let sum = cal.count + 1, let copy = { ...cal } and let { month } = cal there. Unpacking the call itself, let { month } = calendar(...), keeps each name live; unpacking deeper than the names it returns (let { range: { from } } = calendar(...)) reads once, and is refused too.

How to fix it

Read cal.month where it is needed, unpack the call with let { month } = calendar(...), or follow it with let m = derived(() => cal.month).

In a terminal

duolith explain E0178

Mentioned in