mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix error of for_in alias (#10770)
This commit is contained in:
parent
de9aa987bc
commit
5c7881feb7
@ -4358,7 +4358,7 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
||||
}
|
||||
node.scope.update_var_type(node.val_var, node.val_type)
|
||||
} else {
|
||||
sym := c.table.get_type_symbol(typ)
|
||||
sym := c.table.get_final_type_symbol(typ)
|
||||
if sym.kind == .struct_ {
|
||||
// iterators
|
||||
next_fn := sym.find_method('next') or {
|
||||
|
26
vlib/v/tests/for_in_alias_test.v
Normal file
26
vlib/v/tests/for_in_alias_test.v
Normal file
@ -0,0 +1,26 @@
|
||||
enum Nucleotide {
|
||||
a
|
||||
c
|
||||
g
|
||||
t
|
||||
}
|
||||
|
||||
type Codon = []Nucleotide
|
||||
type Gene = []Codon
|
||||
|
||||
fn test_for_in_alias() {
|
||||
mut gene := Gene([
|
||||
Codon([Nucleotide.a, Nucleotide.c, Nucleotide.g]),
|
||||
Codon([Nucleotide.g, Nucleotide.a, Nucleotide.t]),
|
||||
])
|
||||
|
||||
mut ret := []string{}
|
||||
for cdn in gene {
|
||||
println(cdn)
|
||||
ret << '$cdn'
|
||||
}
|
||||
|
||||
assert ret.len == 2
|
||||
assert ret[0] == 'Codon([a, c, g])'
|
||||
assert ret[1] == 'Codon([g, a, t])'
|
||||
}
|
Loading…
Reference in New Issue
Block a user