1
0
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:
Daniel Däschle
2021-02-02 14:42:00 +01:00
committed by GitHub
parent 58b37519e0
commit d477e525bb
13 changed files with 211 additions and 75 deletions

View File

@@ -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'
}