A value converted to any Shape is called through the shape's methods, which declare what
effects they may use. Here the type's method uses more than the shape declares, so calling it
through the shape would hide an effect.
Wrong#
shape Log { fn log(self, s: str) }
struct F { p: str }
fn log(f: F, s: str) uses fs { fs.write(f.p, s) else () }
fn report(l: any Log) { l.log("hi") }
fn main() { report(F { p: "a" }) }Fixed#
shape Log { fn log(self, s: str) uses fs }
struct F { p: str }
fn log(f: F, s: str) uses fs { fs.write(f.p, s) else () }
fn report(l: any Log) uses fs { l.log("hi") }
fn main() uses fs { report(F { p: "a" }) }Common causes#
- A shape method declared without the effects its implementations need.
- An implementation that does I/O where the shape promises purity.