// DOCS NAVIGATION
Visibilidade_
SOURCE: content/docs/reference/04-avancado.md — 04 Avançado / 7. Visibilidade / Visibility
PT-BR:
SpectraLang tem três níveis de visibilidade:
EN-US:
SpectraLang has three visibility levels:
| Modificador / Modifier | Escopo PT-BR | Scope EN-US |
|---|---|---|
| (padrão / default) | Privado — apenas no módulo | Private — current module only |
public | Público — acessível de outros módulos | Public — accessible from other modules |
internal | Interno — acessível dentro do pacote | Internal — accessible within the package |
module minha.biblioteca
// Pública — qualquer módulo pode usar / Public — any module can use
public record Ponto {
public x: int, // campo público / public field
public y: int
}
// Interna — apenas no pacote / Internal — package only
internal func utilitario_interno() returns int {
return 42
}
// Privada — apenas neste módulo / Private — this module only
func helper() returns int {
return utilitario_interno()
}
// Pública com impl público / Public with public impl
public impl Ponto {
public func novo(x: int, y: int) returns Ponto {
Ponto { x: x, y: y }
}
}
Regras de Visibilidade / Visibility Rules
PT-BR:
- Funções públicas não podem expor tipos privados nas assinaturas
- Records públicos não podem expor tipos privados nos campos
- Enums públicos não podem expor tipos privados nas variantes
- Parâmetros genéricos e tipos built-in (
int,float, etc.) são exceções
EN-US:
- Public functions cannot expose private types in their signatures
- Public structs cannot expose private types in fields
- Public enums cannot expose private types in variants
- Generic type parameters and built-in types (
int,float, etc.) are exceptions
// Tipo privado / Private type
record Interno {
dados: int
}
// ERRO: função pública expõe tipo privado / ERROR: public function exposes private type
// public func obter_interno() returns Interno { ... }
// OK: usa tipo built-in / OK: uses builtin type
public func calcular() returns int { return 42
}
// OK: tipo público / OK: public type
public record Publico {
valor: int
}
public func obter_publico() returns Publico { Publico { valor: 1 } }