checker: fix error of for_in alias (#10770)

pull/10772/head
yuyi 2021-07-12 14:17:00 +08:00 committed by GitHub
parent de9aa987bc
commit 5c7881feb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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 {

View 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])'
}