fix(compiler): allow integer coercion in range bounds; use for loops in boko-framework

- sema: range bounds now accept compatible integer types (e.g. int..uint)
  instead of requiring exact type equality.
- hir_lower: derive loop variable type from the common range type.
- boko-framework: replace manual while loops with for loops in Query_Parse,
  Request_Parse, Path_Match and App_Run.
This commit is contained in:
2026-06-17 12:08:36 +03:00
parent 9c632ce389
commit 94e6806dda
3 changed files with 24 additions and 16 deletions
+11 -2
View File
@@ -481,7 +481,15 @@ proc resolveExprType(ctx: var LowerCtx, expr: Expr): Type =
return makeSlice(makeUnknown())
of ekRange:
let loType = ctx.resolveExprType(expr.exprRangeLo)
return makeRange(loType)
let hiType = ctx.resolveExprType(expr.exprRangeHi)
if loType == hiType:
return makeRange(loType)
elif loType.isAssignableTo(hiType):
return makeRange(hiType)
elif hiType.isAssignableTo(loType):
return makeRange(loType)
else:
return makeRange(loType)
of ekTuple:
var elems: seq[Type] = @[]
for e in expr.exprTupleElements:
@@ -1377,7 +1385,8 @@ proc lowerStmt(ctx: var LowerCtx, stmt: Stmt): HirNode =
let inclusive = iterExpr.exprRangeInclusive
# Determine loop variable type from range bounds
let varType = ctx.resolveExprType(iterExpr.exprRangeLo)
let rangeType = ctx.resolveExprType(iterExpr)
let varType = if rangeType.inner.len > 0: rangeType.inner[0] else: ctx.resolveExprType(iterExpr.exprRangeLo)
# Create: var i = lo; while i < hi { body; i = i + 1; }
let initStmt = hirAlloca(varName, varType, loc)
+9 -2
View File
@@ -1007,9 +1007,16 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
of ekRange:
let lo = sema.checkExpr(expr.exprRangeLo, scope)
let hi = sema.checkExpr(expr.exprRangeHi, scope)
if lo != hi:
var rangeType: Type = lo
if lo == hi:
rangeType = lo
elif lo.isAssignableTo(hi):
rangeType = hi
elif hi.isAssignableTo(lo):
rangeType = lo
else:
sema.emitError(expr.loc, "range bounds must have same type")
return makeRange(lo)
return makeRange(rangeType)
of ekCall:
if expr.exprCallCallee == nil:
sema.emitError(expr.loc, "internal error: nil callee in call expression")