1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: add support for alias map keys (#16682)

This commit is contained in:
Swastik Baranwal 2022-12-15 22:23:23 +05:30 committed by GitHub
parent 3643785981
commit bd1d96de0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -3064,6 +3064,10 @@ fn (mut g Gen) map_fn_ptrs(key_typ ast.TypeSymbol) (string, string, string, stri
mut clone_fn := ''
mut free_fn := '&map_free_nop'
match key_typ.kind {
.alias {
alias_key_type := (key_typ.info as ast.Alias).parent_type
return g.map_fn_ptrs(g.table.sym(alias_key_type))
}
.u8, .i8, .char {
hash_fn = '&map_hash_int_1'
key_eq_fn = '&map_eq_int_1'

View File

@ -0,0 +1,16 @@
type String = string
type Rune = rune
fn test_map_key_alias() {
mut str_data := map[string]map[String]string{}
str_data['str'][String('String')] = 'test'
assert '${str_data}' == "{'str': {'String': 'test'}}"
mut i32_data := map[i32]string{}
i32_data[23] = 'num'
assert '${i32_data}' == "{23: 'num'}"
mut rune_data := map[Rune]string{}
rune_data[`A`] = 'rune'
assert '${rune_data}' == "{`A`: 'rune'}"
}