cgen: fix generating invalid Option decls for generic interfaces (#10817)
parent
aca66d503d
commit
ebc34c237b
|
@ -1375,10 +1375,13 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
ast.Import {}
|
ast.Import {}
|
||||||
ast.InterfaceDecl {
|
ast.InterfaceDecl {
|
||||||
// definitions are sorted and added in write_types
|
// definitions are sorted and added in write_types
|
||||||
for method in node.methods {
|
ts := g.table.get_type_symbol(node.typ)
|
||||||
if method.return_type.has_flag(.optional) {
|
if !(ts.info as ast.Interface).is_generic {
|
||||||
// Register an optional if it's not registered yet
|
for method in node.methods {
|
||||||
g.register_optional(method.return_type)
|
if method.return_type.has_flag(.optional) {
|
||||||
|
// Register an optional if it's not registered yet
|
||||||
|
g.register_optional(method.return_type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,3 +63,36 @@ fn test_extract_basic() {
|
||||||
cc := extract_basic(c)
|
cc := extract_basic(c)
|
||||||
assert '$aa | $bb | $cc' == '123 | 456 | 789'
|
assert '$aa | $bb | $cc' == '123 | 456 | 789'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////
|
||||||
|
interface Iterator<T> {
|
||||||
|
next() ?T
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NumberIterator<T> {
|
||||||
|
limit T
|
||||||
|
mut:
|
||||||
|
val T
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut i NumberIterator<T>) next<T>() ?T {
|
||||||
|
if i.val >= i.limit {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
i.val++
|
||||||
|
return i.val
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_iterator_implementation() {
|
||||||
|
mut i := Iterator<int>(NumberIterator<int>{
|
||||||
|
limit: 10
|
||||||
|
})
|
||||||
|
for {
|
||||||
|
if val := i.next() {
|
||||||
|
println(val)
|
||||||
|
} else {
|
||||||
|
println('iterator is done')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue