Summary
Add type aliasing to Grayscale using the alias keyword. An alias creates a
new name for an existing type — purely for readability. The alias and the
original type are fully interchangeable.
Syntax
alias PlayerID = int
alias Point3D = Point
Private aliases (scoped to the declaring file):
Rules
- File-scope only — no aliases inside functions, loops, or blocks
- Public by default,
private restricts to the declaring file
- The alias and the underlying type are identical — fully interchangeable in all contexts
- Can alias any type: primitives, structs, enums, function signatures, containers
- No chained alias resolution issues — an alias of an alias just resolves to the base type
Compiler Changes
- Lexer: Register
alias as a keyword
- Parser: Parse
alias Name = Type as a new top-level declaration node
- Typechecker: Resolve alias references to their underlying type; validate the target type exists
- Codegen: Emit the underlying C type wherever the alias is used (aliases are erased at codegen)
Examples
alias Meters = float
alias Username = string
do calculate_distance(start Meters, end Meters) -> Meters {
if end > start {
return end - start
}
return start - end
}
do main() {
mut distance Meters = calculate_distance(10.0, 25.5)
println("Distance: ${distance}")
}
Since aliases are interchangeable, this also works:
mut distance float = calculate_distance(10.0, 25.5)
Summary
Add type aliasing to Grayscale using the
aliaskeyword. An alias creates anew name for an existing type — purely for readability. The alias and the
original type are fully interchangeable.
Syntax
Private aliases (scoped to the declaring file):
Rules
privaterestricts to the declaring fileCompiler Changes
aliasas a keywordalias Name = Typeas a new top-level declaration nodeExamples
Since aliases are interchangeable, this also works: