feat: generic struct monomorphization + tkUnknown fix

- Add generic struct instantiation (Box<int>, Pair<T,U>) in HIR lowering
- Fix tkUnknown/tkNamed/tkTypeParam ambiguity in sema.nim (qualify with TypeKind)
- Add generics_struct example
- Update Makefile with new example
This commit is contained in:
2026-05-31 10:33:08 +03:00
parent 7ee6a73ea4
commit 9f733aca7d
9 changed files with 136 additions and 15 deletions
+2 -2
View File
@@ -427,7 +427,7 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
for i in 0 ..< argTypes.len:
let paramIdx = i + 1 # skip self
if paramIdx < expectedParams.len:
if not argTypes[i].isAssignableTo(expectedParams[paramIdx]):
if not argTypes[i].isAssignableTo(expectedParams[paramIdx]) and not (argTypes[i].kind in {TypeKind.tkUnknown, TypeKind.tkNamed, TypeKind.tkTypeParam}):
sema.emitError(expr.loc, &"argument {i+1}: expected {expectedParams[paramIdx].toString}, got {argTypes[i].toString}")
return minfo.retType
@@ -451,7 +451,7 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
sema.emitError(expr.loc, &"expected {expectedParams.len} arguments, got {argTypes.len}")
else:
for i in 0 ..< argTypes.len:
if not argTypes[i].isAssignableTo(expectedParams[i]):
if not argTypes[i].isAssignableTo(expectedParams[i]) and not (argTypes[i].kind in {TypeKind.tkUnknown, TypeKind.tkNamed, TypeKind.tkTypeParam}):
sema.emitError(expr.loc, &"argument {i+1}: expected {expectedParams[i].toString}, got {argTypes[i].toString}")
return calleeType.inner[^1]
elif calleeType.kind == tkUnknown: