Skip to content
ZOLO / TE146 Type · error

field accessor visibility widens the stored field

An accessor may inherit or narrow its field visibility, but it cannot expose a private stored field publicly.

Why this fires

An accessor is part of a stored field's API, so it may inherit or narrow the field visibility but cannot make a private field public.

struct Account {
  balance: int {
    pub get // error[TE146]
  }
}

Allowing this would expose a member whose stored field declaration says it is private.

Fix it

Either remove pub from the accessor or make the field public as well:

pub balance: int {
  pub get
}

Use scoped visibility such as pub(mod) when the accessor should be narrower than a public field.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br