From 837fbb04871a0ed79a03c296c413e5a9d67d2b28 Mon Sep 17 00:00:00 2001 From: dimgigov Date: Mon, 1 Jun 2026 00:17:54 +0300 Subject: [PATCH] fix(bootstrap): type compatibility fixes for self-hosting - Allow int32 <-> int and uint32 <-> int/uint comparisons - Allow uint32 <-> int32 comparisons - Allow String indexing (returns char8) - Allow *char8 -> String assignment (C string literal to Bux String) These fixes allow buxc2 (self-hosted compiler) to build successfully. All 14 modules compile; buxc2 binary is 111KB. --- src/sema.nim | 2 ++ src/types.nim | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/sema.nim b/src/sema.nim index 1627a0a..0e0fa8f 100644 --- a/src/sema.nim +++ b/src/sema.nim @@ -883,6 +883,8 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type = return obj.inner[0] elif obj.isPointer: return obj.inner[0] + elif obj.kind == tkStr: + return makeChar8() else: sema.emitError(expr.loc, "cannot index non-slice/non-pointer type") return makeUnknown() diff --git a/src/types.nim b/src/types.nim index 488ef64..5ab24d7 100644 --- a/src/types.nim +++ b/src/types.nim @@ -132,12 +132,25 @@ proc isAssignableTo*(a, b: Type): bool = if a.kind == tkInt and b.kind == tkInt64: return true if a.kind == tkUInt64 and b.kind == tkUInt: return true if a.kind == tkUInt and b.kind == tkUInt64: return true + # int32 <-> int (for convenience in bootstrap) + if a.kind == tkInt32 and b.kind == tkInt: return true + if a.kind == tkInt and b.kind == tkInt32: return true + if a.kind == tkUInt32 and b.kind == tkInt: return true + if a.kind == tkInt and b.kind == tkUInt32: return true + if a.kind == tkUInt32 and b.kind == tkUInt: return true + if a.kind == tkUInt and b.kind == tkUInt32: return true + if a.kind == tkInt32 and b.kind == tkUInt32: return true + if a.kind == tkUInt32 and b.kind == tkInt32: return true # smaller int -> int/uint if b.kind == tkInt and a.kind in {tkInt8, tkInt16, tkInt32}: return true if b.kind == tkUInt and a.kind in {tkUInt8, tkUInt16, tkUInt32}: return true # int <-> uint (for convenience in bootstrap) if a.kind == tkInt and b.kind == tkUInt: return true if a.kind == tkUInt and b.kind == tkInt: return true + # *char8 -> String (C string literal to Bux String) + if a.kind == tkPointer and b.kind == tkStr: + if a.inner.len > 0 and a.inner[0].kind == tkChar8: + return true # numeric exact match required otherwise if a.isNumeric and b.isNumeric: return false # bool across widths