diff --git a/vlib/v/tests/generics_from_modules/genericmodule/take.v b/vlib/v/tests/generics_from_modules/genericmodule/take.v new file mode 100644 index 0000000000..4fad996519 --- /dev/null +++ b/vlib/v/tests/generics_from_modules/genericmodule/take.v @@ -0,0 +1,8 @@ +module genericmodule + +pub fn take(a bool, b T, c T) T { + if a { + return b + } + return c +} diff --git a/vlib/v/tests/generics_from_modules/inference_test.v b/vlib/v/tests/generics_from_modules/inference_test.v new file mode 100644 index 0000000000..1a9e753d57 --- /dev/null +++ b/vlib/v/tests/generics_from_modules/inference_test.v @@ -0,0 +1,35 @@ +module main + +import genericmodule + +fn test_generic_function_from_another_module() { + v1 := genericmodule.take(true, 10, 20) + assert typeof(v1) == 'int' + assert v1 == 10 + v2 := genericmodule.take(false, 10, 20) + assert v2 == 20 +} + +fn test_generic_type_inference_from_another_module() { + v1 := genericmodule.take(true, 10, 20) + assert typeof(v1) == 'int' + assert v1 == 10 + v2 := genericmodule.take(false, 10, 20) + assert v2 == 20 +} + +fn test_inference_with_strings() { + v1 := genericmodule.take(true, 'abc', 'def') + assert typeof(v1) == 'string' + assert v1 == 'abc' + v2 := genericmodule.take(false, 'abc', 'def') + assert v2 == 'def' +} + +fn test_inference_with_f64() { + v1 := genericmodule.take(true, f64(123), 345) + assert typeof(v1) == 'f64' + assert v1 == 123 + v2 := genericmodule.take(false, f64(123), 345) + assert v2 == 345 +}