Skip to content

Commit ac00d44

Browse files
authored
cgen: fix generic key's type with in operation (fix #24983) (#25011)
1 parent af0a73f commit ac00d44

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

vlib/v/gen/c/infix.v

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,15 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
614614
} else if right.unaliased_sym.kind == .map {
615615
g.write('_IN_MAP(')
616616
if !left.typ.is_ptr() {
617-
styp := g.styp(node.left_type)
617+
mut sym_map := g.table.sym(node.right_type)
618+
if sym_map.info is ast.Alias {
619+
sym_map = g.table.sym((sym_map.info as ast.Alias).parent_type)
620+
}
621+
styp := g.styp(if sym_map.info is ast.Map {
622+
(sym_map.info as ast.Map).key_type
623+
} else {
624+
node.left_type
625+
})
618626
g.write('ADDR(${styp}, ')
619627
g.expr(node.left)
620628
g.write(')')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import datatypes
2+
3+
fn x() {
4+
mut set1 := datatypes.Set[string]{}
5+
set1.add('')
6+
assert set1.exists('')
7+
}
8+
9+
fn y() {
10+
mut set2 := datatypes.Set[int]{}
11+
set2.add(1)
12+
assert set2.exists(1)
13+
}
14+
15+
fn test_main() {
16+
x()
17+
y()
18+
}

0 commit comments

Comments
 (0)