// #target: macos-x64 module test; import std::io; define Callback1 = fn double(double x); define Callback2 = fn int(int y); macro test2(y) { var $Type = $typeof(y); return fn $Type($typeof(y) x) { return x * x; }; } macro test($Type) { $Type z = fn (x) { return x * x; }; return z; } fn void main() { io::printfn("val: %d", test(Callback2)(3)); io::printfn("val: %s", test(Callback1)(3.3)); io::printfn("val: %s", test(Callback1)(3.3)); io::printfn("val: %d", test2(1)(3)); io::printfn("val: %d", test2(1)(3)); io::printfn("val: %s", test2(1.0)(3.3)); } /* #expect: test.ll store i32 (i32)* @"test_test$lambda1", i32 (i32)** %z, align 8 %1 = call i32 %0(i32 3) store double (double)* @"test_test$lambda2", double (double)** %z4, align 8 %14 = call double %13(double 3.300000e+00) store double (double)* @"test_test$lambda2", double (double)** %z14, align 8 %27 = call double %26(double 3.300000e+00) %39 = call i32 @"test_test2$lambda3"(i32 3) %51 = call i32 @"test_test2$lambda3"(i32 3) %63 = call double @"test_test2$lambda4"(double 3.300000e+00) define internal double @"test_test2$lambda4"(double %0) #0 { define internal i32 @"test_test2$lambda3"(i32 %0) #0 { define internal double @"test_test$lambda2"(double %0) #0 { define internal i32 @"test_test$lambda1"(i32 %0) #0 {