DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B0702: some fields of a struct are pub and some are not

Catalog status: active. Default severity: error. Stable name: mixed-field-visibility. Family: Syntax and source text.

A pub struct either shows all its fields, which makes it a public record, or none, which makes it a private type whose fields only its package sees (as in Ada, where a private type is all or nothing). It cannot show some fields and hide others.

Example (Varc)

package Accounts {
    pub struct Account {
        pub id: Natural,
        balance: Integer,
    }
}

What to do

Mark every field pub, or none. To give clients one field of a private type, give them a function: pub fn id(a: Account) -> Natural = a.id;.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See syntax and source text, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.