mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker/gen: fix generic struct init (#8322)
This commit is contained in:
@@ -44,10 +44,27 @@ fn (v Foo) new<T>() T {
|
||||
|
||||
fn test_generic_method_with_map_type() {
|
||||
foo := Foo{}
|
||||
assert foo.new<map[string]string>() == map[string]string{}
|
||||
mut a := foo.new<map[string]string>()
|
||||
assert a == map[string]string{}
|
||||
assert a.len == 0
|
||||
a['a'] = 'a'
|
||||
assert a.len == 1
|
||||
assert a['a'] == 'a'
|
||||
}
|
||||
|
||||
fn test_generic_method_with_array_type() {
|
||||
foo := Foo{}
|
||||
assert foo.new<[]string>() == []string{}
|
||||
mut a := foo.new<[]string>()
|
||||
assert a == []string{}
|
||||
assert a.len == 0
|
||||
a << 'a'
|
||||
assert a.len == 1
|
||||
assert a[0] == 'a'
|
||||
}
|
||||
|
||||
fn test_generic_method_with_struct_type() {
|
||||
foo := Foo{}
|
||||
mut a := foo.new<Person>()
|
||||
a.name = 'a'
|
||||
assert a.name == 'a'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user