feat: generic methods on generic structs + method call auto-addressing

- Auto-register func Type_Method<T>(self: *Type<T>) as methods in sema
- Add type param awareness to sema resolveType for generic function bodies
- Add lazy monomorphization for generic struct method calls in HIR lowering
- Track varTypeExprs in LowerCtx for local variable type inference
- Fix ekSelf in both sema and hir_lower to resolve actual parameter type
- Fix lowerFunc to use substituteType for param/return types (handles pointers to generic structs)
- Auto-address value receivers when method expects pointer (e.g., b.Get() where self: *Box<T>)
- Add C forward declarations for all functions to fix ordering issues
- Relax type checks for tkTypeParam in assignments and arguments
- Update generics_struct example with Box_Get, Box_Set, Pair_GetFirst/Second
This commit is contained in:
2026-05-31 11:57:52 +03:00
parent 9f733aca7d
commit af14f392f6
5 changed files with 220 additions and 35 deletions
+28 -2
View File
@@ -10,15 +10,41 @@ struct Pair<T, U> {
second: U,
}
func Box_Get<T>(self: *Box<T>) -> T {
return self.value;
}
func Box_Set<T>(self: *Box<T>, value: T) {
self.value = value;
}
func Pair_GetFirst<T, U>(self: *Pair<T, U>) -> T {
return self.first;
}
func Pair_GetSecond<T, U>(self: *Pair<T, U>) -> U {
return self.second;
}
func Main() -> int {
let b: Box<int> = Box<int> { value: 42 };
PrintLine("Box value:");
PrintInt(b.value);
PrintInt(b.Get());
PrintLine("");
b.Set(100);
PrintLine("Box after Set(100):");
PrintInt(b.Get());
PrintLine("");
let p: Pair<int, String> = Pair<int, String> { first: 10, second: "hello" };
PrintLine("Pair first:");
PrintInt(p.first);
PrintInt(p.GetFirst());
PrintLine("");
let bp: *Box<int> = &b;
PrintLine("Box via pointer:");
PrintInt(bp.Get());
PrintLine("");
return 0;