mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
Add assignments
This commit is contained in:
parent
6d2a2fe474
commit
0bf9aed35e
6 changed files with 113 additions and 32 deletions
|
|
@ -557,6 +557,34 @@ export function checkBody(
|
|||
span: expr.span,
|
||||
};
|
||||
}
|
||||
case "assign": {
|
||||
const lhs = this.expr(expr.lhs);
|
||||
const rhs = this.expr(expr.rhs);
|
||||
|
||||
infcx.assign(lhs.ty!, rhs.ty!, expr.span);
|
||||
|
||||
switch (lhs.kind) {
|
||||
case "ident":
|
||||
if (lhs.value.res!.kind !== "local") {
|
||||
throw new CompilerError("cannot assign to items", expr.span);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
throw new CompilerError(
|
||||
"invalid left-hand side of assignment",
|
||||
lhs.span
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...expr,
|
||||
kind: "assign",
|
||||
lhs,
|
||||
rhs,
|
||||
ty: TY_UNIT,
|
||||
};
|
||||
}
|
||||
case "block": {
|
||||
currentNestingDepth++;
|
||||
const prevLocalTysLen = localTys.length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue