feat: add borrow test example, fix borrow &mut parsing order

- examples/borrow.bux: working borrow expression example
- tests/borrow_test.nim: add 4 new tests for borrow & @[Shared]
- parser.nim: fix borrow parsing order (& before mut)
- Build verified: example compiles and runs
This commit is contained in:
2026-06-07 17:50:27 +03:00
parent 46814b2abc
commit bfe87a8acb
5 changed files with 37 additions and 1 deletions
+9
View File
@@ -1200,6 +1200,15 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
let operand = sema.checkExpr(expr.exprAwaitOperand, scope)
# await on a task handle returns *void (result pointer)
return makePointer(makeVoid())
of ekBorrow:
let operand = sema.checkExpr(expr.exprBorrowOperand, scope)
# borrow &mut expr returns the same type as the original (reference)
# The borrow is tracked in the borrow checker
if sema.checkedFunc and expr.exprBorrowMutable:
# Track: variable "operand" is mutably borrowed here
# For now, just validate the type
discard
return operand
of ekSpread:
return sema.checkExpr(expr.exprSpreadOperand, scope)