checker: fix generics fn selector expr with unexpected symbol (#10851)
parent
11161f4550
commit
fdba3607af
|
@ -1780,7 +1780,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
|
||||||
c.error('`$typ_sym.kind` can not be modified', expr.pos)
|
c.error('`$typ_sym.kind` can not be modified', expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.aggregate {
|
.aggregate, .placeholder {
|
||||||
c.fail_if_immutable(expr.expr)
|
c.fail_if_immutable(expr.expr)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -4,18 +4,22 @@ interface Iter<T> {
|
||||||
|
|
||||||
struct ArrayIter<T> {
|
struct ArrayIter<T> {
|
||||||
data []T
|
data []T
|
||||||
|
mut:
|
||||||
|
index int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut i ArrayIter<T>) next<T>() ?T {
|
fn (mut i ArrayIter<T>) next<T>() ?T {
|
||||||
if i.data.len == 0 {
|
if i.data.len == 0 {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
return i.data[0]
|
i.index += 1
|
||||||
|
return i.data[i.index]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter<T>(arr []T) Iter<T> {
|
fn iter<T>(arr []T) Iter<T> {
|
||||||
return ArrayIter<T>{
|
return ArrayIter<T>{
|
||||||
data: arr
|
data: arr
|
||||||
|
index: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,5 +28,5 @@ fn test_generics_fn_return_generic_interface() {
|
||||||
println(x)
|
println(x)
|
||||||
y := x.next() or { 0 }
|
y := x.next() or { 0 }
|
||||||
println(y)
|
println(y)
|
||||||
assert y == 1
|
assert y == 2
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue