fix(bootstrap): avoid emitting malformed Slice_T* typedefs

- Strip pointer suffix when scanning for slice types in C backend
- Skip slice typedefs already emitted from module.structs

Fixes _test_slice
This commit is contained in:
2026-06-14 17:23:58 +03:00
parent 44bac83471
commit 2c8223f94e
+9 -3
View File
@@ -2,7 +2,7 @@
## Emits clean, well-structured C code from LIR instructions.
## Since LIR is already linear and low-level, C emission is straightforward.
import std/[strutils, strformat, tables, sequtils]
import std/[strutils, strformat, tables, sequtils, sets]
import lir, hir, types, token
type
@@ -570,12 +570,18 @@ proc emitModule*(be: var LirCBackend, builder: LirBuilder, module: HirModule): s
# Slice types (collect from functions/structs)
# Simple: scan function params/returns for slice types
var sliceTypes: seq[tuple[name: string, elem: string]] = @[]
var structNames: HashSet[string]
for s in module.structs:
structNames.incl(s.name)
for f in module.funcs:
for p in f.params:
let ct = typeToCStr(p.typ)
var ct = typeToCStr(p.typ)
# Strip pointer/reference suffix to find the base slice type.
while ct.endsWith("*"):
ct = ct[0..^2]
if ct.startsWith("Slice_"):
let elem = ct[6 .. ^1]
if not sliceTypes.anyIt(it.name == ct):
if not sliceTypes.anyIt(it.name == ct) and not structNames.contains(ct):
sliceTypes.add((ct, elem))
if sliceTypes.len > 0:
for st in sliceTypes: