@@ -6200,6 +6200,53 @@ fn main() -> u5 {
6200
6200
IsOkAndHolds (HasTypeInfo (HasNodeWithType (" var" , " uN[5]" ))));
6201
6201
}
6202
6202
6203
+ TEST (TypecheckV2Test, ImportParametricFunctionWithMultipleInvocations) {
6204
+ constexpr std::string_view kImported = R"(
6205
+ pub fn add_one(x: u32) -> u32 { x + 1 }
6206
+
6207
+ pub fn some_function<N: u32, M: u32 = { add_one(N) }>() -> uN[M] { uN[M]:0 }
6208
+
6209
+ pub fn another_fn() -> u3 { some_function<2>() }
6210
+
6211
+ pub fn parametric_call<M: u32>() -> uN[M] { some_function<3, M>() }
6212
+
6213
+ )" ;
6214
+ constexpr std::string_view kInt = R"(
6215
+ import imported;
6216
+
6217
+ pub fn mid() -> u32 { imported::some_function<31>() }
6218
+
6219
+ pub fn default_import<N: u32, M: u32 = { imported::add_one(N) }>() -> uN[M] { uN[M]:0 }
6220
+
6221
+ )" ;
6222
+ constexpr std::string_view kProgram = R"(
6223
+ import imported;
6224
+ import int;
6225
+
6226
+ const VAR = imported::some_function<4>();
6227
+ const VAR2 = imported::some_function<3, 6>();
6228
+ const VAR3 = imported::some_function<7>();
6229
+ const VAR4 = imported::another_fn();
6230
+ const VAR5 = imported::parametric_call<15>();
6231
+ const VAR6 = int::mid();
6232
+
6233
+ fn main() -> u26 {
6234
+ int::default_import<25>()
6235
+ }
6236
+ )" ;
6237
+ ImportData import_data = CreateImportDataForTest ();
6238
+ XLS_EXPECT_OK (TypecheckV2 (kImported , " imported" , &import_data).status ());
6239
+ XLS_EXPECT_OK (TypecheckV2 (kInt , " int" , &import_data).status ());
6240
+ EXPECT_THAT (
6241
+ TypecheckV2 (kProgram , " main" , &import_data),
6242
+ IsOkAndHolds (HasTypeInfo (AllOf (
6243
+ HasNodeWithType (" VAR" , " uN[5]" ), HasNodeWithType (" VAR2" , " uN[6]" ),
6244
+ HasNodeWithType (" VAR4" , " uN[3]" ), HasNodeWithType (" VAR5" , " uN[15]" ),
6245
+ HasNodeWithType (" VAR6" , " uN[32]" ),
6246
+ HasNodeWithType (" int::default_import<25>()" , " uN[26]" ),
6247
+ HasNodeWithType (" VAR3" , " uN[8]" )))));
6248
+ }
6249
+
6203
6250
TEST (TypecheckV2Test, ImportParametricFunction) {
6204
6251
constexpr std::string_view kImported = R"(
6205
6252
pub fn some_function<N: u32>() -> uN[N] { uN[N]:0 }
0 commit comments