mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
This commit is contained in:
parent
feb409071d
commit
e2434a8256
2 changed files with 15 additions and 1 deletions
|
@ -422,7 +422,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
g.writeln('${field_accessor}str[${i}];')
|
g.writeln('${field_accessor}str[${i}];')
|
||||||
}
|
}
|
||||||
} else if node.kind in [.struct, .interface] {
|
} else if node.kind in [.struct, .interface] {
|
||||||
cond_type_sym := g.table.sym(node.cond_type)
|
cond_type_sym := g.table.final_sym(node.cond_type)
|
||||||
next_fn := cond_type_sym.find_method_with_generic_parent('next') or {
|
next_fn := cond_type_sym.find_method_with_generic_parent('next') or {
|
||||||
verror('`next` method not found')
|
verror('`next` method not found')
|
||||||
return
|
return
|
||||||
|
|
|
@ -11,6 +11,8 @@ mut:
|
||||||
idx int
|
idx int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AliasLineIterator = LineIterator
|
||||||
|
|
||||||
pub fn (mut line_iterator LineIterator) next() ?string {
|
pub fn (mut line_iterator LineIterator) next() ?string {
|
||||||
if line_iterator.idx >= line_iterator.lines.len {
|
if line_iterator.idx >= line_iterator.lines.len {
|
||||||
return none
|
return none
|
||||||
|
@ -31,6 +33,12 @@ fn iterator_as_concrete_type() LineIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn iterator_as_alias_concrete_type() AliasLineIterator {
|
||||||
|
return AliasLineIterator(LineIterator{
|
||||||
|
lines: ['alias']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn test_main() {
|
fn test_main() {
|
||||||
mut out := []string{}
|
mut out := []string{}
|
||||||
for line in iterator_as_interface() {
|
for line in iterator_as_interface() {
|
||||||
|
@ -64,4 +72,10 @@ fn test_main() {
|
||||||
|
|
||||||
assert out[4] == 'LINE: interface'
|
assert out[4] == 'LINE: interface'
|
||||||
assert out[5] == 'LINE: concrete'
|
assert out[5] == 'LINE: concrete'
|
||||||
|
|
||||||
|
for _, line in iterator_as_alias_concrete_type() {
|
||||||
|
out << 'LINE: ${line}'
|
||||||
|
}
|
||||||
|
|
||||||
|
assert out[6] == 'LINE: alias'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue