Lyricdev
GitHub

LYR-MIG0320

a method that writes under an interface

hint · spec 14-cli

A note of lyric fix --from-4: a method of a class writes the object's state, and the interface it answers declares it without mut.

Explanation

In Lyric 4 a method of a class wrote its fields without saying so, whatever the interface declared. In Lyric 5 a method that writes this is a mut fn (LYR-SEM0019), and a conformance repeats what the interface says (LYR-SEM0042), so neither side can change alone.

Declare it mut fn in the interface and in every type that answers it. A struct that answers it then needs a var to call it on. Where the interface is another library's, the state has to move: into another object that the method reaches through a field.

Example

by hand[LYR-MIG0320] main.lyr:8:8: 'hit' writes the object's state, and the interface 'Damageable' declares it without 'mut'; Lyric 5 has a method that writes declared 'mut fn', and a conformance repeats what the interface says — declare it 'mut fn' in 'Damageable' and in every type that answers it