cgen: fix generic key's type with in operation (fix #24983) (#25011)

This commit is contained in:
Krchi 2025-08-01 01:09:00 +08:00 committed by GitHub
parent af0a73f04f
commit ac00d441ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -614,7 +614,15 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
} else if right.unaliased_sym.kind == .map {
g.write('_IN_MAP(')
if !left.typ.is_ptr() {
styp := g.styp(node.left_type)
mut sym_map := g.table.sym(node.right_type)
if sym_map.info is ast.Alias {
sym_map = g.table.sym((sym_map.info as ast.Alias).parent_type)
}
styp := g.styp(if sym_map.info is ast.Map {
(sym_map.info as ast.Map).key_type
} else {
node.left_type
})
g.write('ADDR(${styp}, ')
g.expr(node.left)
g.write(')')

View File

@ -0,0 +1,18 @@
import datatypes
fn x() {
mut set1 := datatypes.Set[string]{}
set1.add('')
assert set1.exists('')
}
fn y() {
mut set2 := datatypes.Set[int]{}
set2.add(1)
assert set2.exists(1)
}
fn test_main() {
x()
y()
}