fix: algebraic enum C backend and sema field type resolution

- Fix sema.nim: use objType.name instead of obj.name for algebraic enum
  tag/data field types (was generating _Tag instead of EnumName_Tag)
- Fix c_backend.nim: emit enum definitions before struct definitions
  to allow structs to reference algebraic enum types
This commit is contained in:
2026-06-05 22:47:37 +03:00
parent 154579b30d
commit 1f64f4707e
2 changed files with 15 additions and 7 deletions
+3 -3
View File
@@ -1086,11 +1086,11 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
elif sym.decl.kind == dkEnum:
# Algebraic enum fields
if expr.exprFieldName == "tag":
return makeNamed(obj.name & "_Tag")
return makeNamed(objType.name & "_Tag")
elif expr.exprFieldName == "data":
return makeNamed(obj.name & "_Data")
return makeNamed(objType.name & "_Data")
else:
sema.emitError(expr.loc, &"enum '{obj.name}' has no field '{expr.exprFieldName}'")
sema.emitError(expr.loc, &"enum '{objType.name}' has no field '{expr.exprFieldName}'")
elif sym.decl.kind == dkUnion:
# Union fields
for f in sym.decl.declUnionFields: