Files
bux-lang/examples/generics_struct.bux
T
dimgigov 9f733aca7d 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
2026-05-31 10:33:08 +03:00

26 lines
485 B
Plaintext

// Generic structs - Box<T> and Pair<T, U>
import Std::Io::{PrintLine, PrintInt};
struct Box<T> {
value: T,
}
struct Pair<T, U> {
first: T,
second: U,
}
func Main() -> int {
let b: Box<int> = Box<int> { value: 42 };
PrintLine("Box value:");
PrintInt(b.value);
PrintLine("");
let p: Pair<int, String> = Pair<int, String> { first: 10, second: "hello" };
PrintLine("Pair first:");
PrintInt(p.first);
PrintLine("");
return 0;
}