---
title: "Visibility"
description: "Control whether a declaration can be used outside its source file."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.atoll.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Visibility

Every declaration, and every field and method, has one of three
visibilities:

| Written | Who can use it |
| --- | --- |
| `pub` | any module that imports it |
| `internal` | every module of the same package |
| `private` | only the file that declares it |

A declaration written with none of the three is `internal`: every module
of its package can use it, and `pub` is the only way to export. This is
edition 2026's rule, and 2026 is the one edition, which a manifest that
states none is read under.

```atoll
pub struct Money {
    cents int
}

private fn cents_of(m Money) int {
    return m.cents
}

pub fn total(items []Money) Money {
    mut acc := 0
    for m in items {
        acc = acc + cents_of(m)
    }
    return Money { cents: acc }
}

fn main() int {
    sum := total([Money { cents: 1999 }, Money { cents: 450 }])
    println("cents: ${sum.cents}")
    return sum.cents
}
```

`Money` and `total` may be imported anywhere. `cents_of` may be used only inside
this file. `main` has no marker, so it takes the package's default.

## The boundary is the file

`private` is enforced per **file**, not per directory. Sibling files in the
same module see each other's `pub` and `internal` names without an import,
and nothing private at all.

| Reference to `cents_of` from… | Result |
| --- | --- |
| the same file | resolves |
| a sibling file in the same directory | `ATOLL1078`: private to its file |
| a named import in another module | `ATOLL1078`, at the import |
| a module-namespace member (`money.cents_of`) | `ATOLL1078` |

In the [example project](https://docs.atoll.workreef.dev/language/modules/#the-example-project), `cents_of` is
declared in `money/amount.at`. Call it from `money/tax.at`, the other file of the
same module, and the project stops compiling:

```atoll project=ledger file=money/tax.at refused=ATOLL1078
const RATE_BP: int = 825

fn tax_on(m Money) Money {
    return Money { cents: cents_of(m) * RATE_BP / 10000 }
}

fn with_tax(m Money) Money {
    return m.plus(tax_on(m))
}
```

```text output
error[ATOLL1078]: `cents_of` is private to `money/amount.at`, so only that file can use it at money/tax.at:4:27
  help: mark it `internal` to share it with every module of this package
1 error(s) found
```

The error names where the declaration is, so it is never mistaken for a name
that does not exist. To share a helper between files, or between the modules of
a package, without exporting it, mark it `internal`.

## `internal`: shared within a package

An `internal` declaration is visible to every module of its package, and to
nothing outside it. Mark the ledger's `usd` `internal`:

```atoll project=ledger file=money/amount.at
pub struct Money {
    pub cents int

    pub fn dollars(&self) int {
        return self.cents / 100
    }

    pub fn plus(&self, other Money) Money {
        return Money { cents: self.cents + other.cents }
    }
}

internal fn usd(dollars int, cents int) Money {
    return Money { cents: dollars * 100 + cents }
}

private fn cents_of(m Money) int {
    return m.cents
}

pub fn total(items []Money) Money {
    mut acc := 0
    for m in items {
        acc = acc + cents_of(m)
    }
    return Money { cents: acc }
}
```

The ledger itself still checks, and `shop`, another package that depends on it
and imports `usd`, is refused:

```text output
$ atoll check shop
error[ATOLL1078]: `usd` is internal to `example.dev/ledger`, so only that package's modules can use it at shop/main.at:1:1
  help: a declaration with no `pub` is internal to its package: if that package is yours, export it with `pub fn usd`; if it is not, use what the package exports
1 error(s) found
```

A directory named `internal` closes the modules under it, as in Go: a module
whose path has an `internal` segment can be imported only by modules under that
segment's parent. `example.dev/ledger/internal/fmt` is importable from
`example.dev/ledger` and its other modules, and `example.dev/ledger/report/internal`
only from `example.dev/ledger/report` and below — whatever the declarations in
them say.

## Where the modifier goes

`pub`, `internal` and `private` apply to top-level functions, structs, enums,
errors, constants, type aliases, and traits. Place the modifier after any
decorators and before the declaration keyword:

```atoll
private const RATE_BP: int = 825

private type Basis = int

private error DecodeError {
    InvalidHeader
}

@inline
private fn scale(cents int, bp Basis) int {
    return cents * bp / 10000
}

pub struct Money {
    cents int
}

pub fn with_tax(m Money) Money {
    return Money { cents: m.cents + scale(m.cents, RATE_BP) }
}

fn main() int {
    due := with_tax(Money { cents: 1999 })
    println("cents: ${due.cents}")
    return due.cents
}
```

Everything private here — the rate, the `Basis` alias, the error, the helper —
is invisible one file away. `Money` and `with_tax` are the exported surface.

## Members are type-private

`private` on a field or method hides it from everything that is not a
method of that type. Sibling files, `main`, and methods of other types
cannot read the field or call the method. Methods of the type can —
including an inherent `impl`, a receiver-prefix `fn Type.m`, a static
constructor, and an `impl Trait for Type`.

```atoll
struct Account {
    private cents  int
    holder string

    fn open(holder string) Account {
        return Account { cents: 0, holder: holder.clone() }
    }

    private fn raw(&self) int {
        return self.cents
    }

    fn balance(&self) int {
        return self.raw()
    }
}

fn main() int {
    a := Account.open("ada")
    println("${a.holder} ${a.balance()}")
    return a.balance()
}
```

Reaching for the field from outside is `ATOLL3030`:

```atoll fail
struct Account {
    private cents int
}

fn main() void {
    a := Account { cents: 100 }
    println("${a.cents}")
}
```

Calling the private method from outside is `ATOLL3031`.

**A type's private members are its package's own.** An `impl` is a method of
its type, which is how it reaches the type's private members, but only when it
is written in the type's package. A package that depends on `bank` and writes
`impl Peek for bank.Account` is not a method of `Account` for this purpose: if
its body reads `Account`'s private field or calls its private method, the
compiler warns, at any optimization level, with the same `ATOLL3030` or
`ATOLL3031`, and the program still compiles and runs the same. It is a warning
and not an error because a library author sometimes hides something they
should not have; it stays a warning until the language has an escape hatch or
an edition to make it stricter. The warning names the type, the file that
declares it and the package whose members they are, and says to ask that
package for what the `impl` needs. An `impl` in the type's own package, and
code derived for the type, say nothing.

The same holds for a write, a struct literal, a closure in the `impl`, and a
generic type. An `impl` that uses only what the type exports with `pub` is
fine, and so is one in the type's own package, in whichever of its files.

A field or method can also be `internal`, visible to every module of the
package. There is no protected tier and no friend mechanism. A helper that is
not a method of the type is a top-level function, as `cents_of` is above — it
cannot see private fields; pass the values it needs.

## `pub` is what exports

What another package may use is what is written `pub`; everything else a
package declares is its own, so a helper never becomes API by accident:

```atoll
pub struct Booking {
    id    int
    seats int
}

pub fn open_booking(id int) Booking {
    return Booking { id: id, seats: default_seats() }
}

private fn default_seats() int {
    return 2
}

fn main() void {
    booking := open_booking(4)
    println("${booking.id}/${booking.seats}")
}
```

No modifier grants host capabilities or bypasses a dependency's own
visibility. An imported declaration keeps the identity and visibility of its
defining module; to make it part of your module's surface, re-export it with
`pub import` (see [Imports](https://docs.atoll.workreef.dev/language/modules/imports/#re-export)).

## A private type in a public signature

A function can be more visible than a type its signature names. Given
`secret/token.at`:

```atoll project=vis file=secret/token.at
private struct Token {
    id int
}

pub fn issue(id int) Token {
    return Token { id: id }
}

pub fn token_id(t Token) int {
    return t.id
}
```

another module can import the two public functions, hold the value, and pass it
back. What it cannot do is name the type, so each function is warned:

```text output
warning[ATOLL1087]: `issue` is public, and its signature names `Token`, which is private to `secret/token.at` — a caller can hold the value and cannot name its type at secret/token.at:5:8
  help: make `Token` `pub`, or make `issue` no more visible than `Token`
warning[ATOLL1087]: `token_id` is public, and its signature names `Token`, which is private to `secret/token.at` — a caller can hold the value and cannot name its type at secret/token.at:9:8
  help: make `Token` `pub`, or make `token_id` no more visible than `Token`
OK (2 diagnostics)
```

It is a warning and not an error, so this still compiles and runs:

```atoll project=vis file=main.at
import example.dev/vis/secret.{issue, token_id}

fn main() int {
    t := issue(7)
    println("id: ${token_id(t)}")
    return token_id(t)
}
```

```text output
$ atoll run vis/main.at
id: 7
atoll run: `main` returned 7
```

Add `Token` to that import, and the import fails:

```atoll project=vis file=main.at refused=ATOLL1078
import example.dev/vis/secret.{issue, token_id, Token}

fn main() int {
    t: Token = issue(7)
    return token_id(t)
}
```

```text output
…
error[ATOLL1078]: `Token` is private to `secret/token.at`, so only that file can use it at main.at:1:1
  help: `private` keeps a declaration to its own file: mark it `internal` to share it with its package, or `pub` to export it
1 error(s) found
```

So the value is usable and unnameable: no annotation, no local variable with an
explicit type, no wrapper struct field. The warning says so where the signature is
written, which is the one place it can be fixed.

## What a public name commits you to

Visibility says whether a name is reachable. It does not freeze the contract
behind it, so review the whole surface before exporting:

| Public declaration | Callers depend on |
| --- | --- |
| Function | Parameters, mutation, success type, error type, effect row, bounds |
| Struct | Type identity, fields, value behavior |
| Enum or error | Variants, payloads, exhaustiveness |
| Trait | Requirements, defaults, supertraits, associated items |
| Alias | Transparency or distinct identity, and its target |
| Constant | Name, type, value |

Public declarations also join module-wide collision checking across sibling
files, so choose names at module scope rather than file scope.

## Changing visibility

Making a public declaration private breaks external imports *and* same-module
sibling references, each reported as `ATOLL1078` at the use. Before tightening,
search for named imports, namespace member access, and unqualified same-module
uses; move the consumers in the same change so the review reads as one decision.
`atoll api diff` reports a narrowed declaration as a major change.

Before widening, check naming, explicit signature types, error and effect
stability, and module ownership. Making a helper public can create downstream
dependencies and trait-coherence conflicts even when its body never changes.

Moving a public declaration between files in the same directory preserves its
import path. Moving it to another directory changes that path — see
[Modules](https://docs.atoll.workreef.dev/language/modules/).

Source: https://docs.atoll.workreef.dev/language/modules/visibility/index.mdx
