Learn Aero / Variables & Types
Variables & Types
Declaring Variables
Aero declares variables with let; the type can be inferred:
let x = 1;
print(x); // 输出 1Four basic types:
i64 | 64-bit signed integer | 42, -7 |
i32 | 32-bit signed integer | integers, decided by annotation |
bool | boolean | true, false |
str | string | "hello" |
The Important Rule of Type Inference
Integer literals are "flexible":
let x = 1; // x 是 i64
let y: i32 = 1; // 合法!字面量 1 可以适配 i32
let z: i32 = x; // 报错!x 已经是 i64,塞进 i32 是隐式窄化Rule: once a type is determined, it will never be narrowed again. Implicit narrowing is the most common source of bugs in C/C++, and Aero chooses to stop it at compile time.
Explicit Annotations
let n: i64 = 10000000000; // 十亿级,必须 i64
let small: i32 = 5;
let flag: bool = true;
let name: str = "Aero";Variables Can Be Reassigned
let x = 1;
x = x + 1;
print(x); // 输出 2On assignment the new value's type must match the original type; narrowing is not allowed.
Block Scoping
let a = 1;
if (true) {
let b = 2;
print(a + b); // 输出 3
}
// print(b); // 错误:b 在这里不存在Declaring two variables with the same name in the same scope is not allowed.
No const
Aero 0.1 has no const; every variable can be reassigned. If you want "read-only", rely on convention rather than compiler enforcement.