pub enum Type {
}Variants§
Int
Float
Str
Bool
Unit
Result(Box<Type>, Box<Type>)
Option(Box<Type>)
List(Box<Type>)
Tuple(Vec<Type>)
Map(Box<Type>, Box<Type>)
Vector(Box<Type>)
Fn(Vec<Type>, Box<Type>, Vec<String>)
Var(String)
Invalid
Named
User-defined or builtin named type. The id is Some once the
typechecker has resolved the reference against the program’s
crate::ir::SymbolTable (#138 phase B). The id is None for
transient parser output (before typecheck has run), for builtin
record types (HttpResponse, Header, Tcp.Connection,
Buffer, …) that aren’t registered in the user-program symbol
table, and for stamps the checker couldn’t resolve.
Identity:
- two
Namedwith bothid = Somecompare byid(typed identity — cross-module same-bare-name types stay distinct); - otherwise fall back to source-faithful name comparison, with
the historical suffix tolerance for
BarevsModule.Bare.
Implementations§
Source§impl Type
impl Type
Sourcepub fn named(name: impl Into<String>) -> Self
pub fn named(name: impl Into<String>) -> Self
Build a Type::Named whose identity has not been resolved
against a SymbolTable (parser output, builtins, in-flight
stamps). Equivalent to Named { id: None, name: name.into() }.
Sourcepub fn named_resolved(id: TypeId, name: impl Into<String>) -> Self
pub fn named_resolved(id: TypeId, name: impl Into<String>) -> Self
Build a Type::Named resolved against the program’s
SymbolTable. Caller is responsible for ensuring name is the
canonical form (symbol_table.type_entry(id).key.canonical()).
Sourcepub fn named_name(&self) -> Option<&str>
pub fn named_name(&self) -> Option<&str>
Source-faithful name of a Named ("Shape" / "A.Shape" /
"HttpResponse"); None for any non-Named variant.
Sourcepub fn named_id(&self) -> Option<TypeId>
pub fn named_id(&self) -> Option<TypeId>
Resolved TypeId of a Named, if any. None for unresolved
references and for any non-Named variant.
Sourcepub fn compatible(&self, other: &Type) -> bool
pub fn compatible(&self, other: &Type) -> bool
a.compatible(b) — can a value of type self be used where other is expected?
Two concrete types must be equal (structurally) to be compatible. Type variables
are resolved by the type checker at call sites, not by this raw relation.
Iron — A4: Type::Invalid is the checker’s “already-errored”
sentinel and matches anything. Without this, a single bad
expression would fan its Invalid type out through every
downstream .compatible(...) check and produce a chain of
duplicate diagnostics.