v2 / vlib / v / tests / generics / generics_method_on_generic_structs_test.v
32 lines · 26 sloc · 554 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import math
2import datatypes
3
4struct Foo {
5 a int
6}
7
8struct Bar[T] {
9 a int
10}
11
12fn (b Bar[T]) pop() {}
13
14fn test_bar_foo_works_even_when_datatypes_is_imported_that_also_has_pop_methods() {
15 mut a := Bar[Foo]{}
16 println(a)
17 assert true
18}
19
20fn test_datatypes_can_be_used_without_interfering_with_local_generic_structs() {
21 mut stack := datatypes.Stack[int]{}
22 stack.push(1)
23 println(stack)
24 assert true
25}
26
27fn test_generic_type_inference_on_generic_function_from_another_module_still_works() {
28 x := -123
29 a := math.abs(x)
30 assert x == -123
31 assert a == 123
32}
33