checker: fix generics fn selector expr with unexpected symbol (#10851)

pull/10842/head^2
yuyi 2021-07-19 14:16:15 +08:00 committed by GitHub
parent 11161f4550
commit fdba3607af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -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)
}
}
.aggregate {
.aggregate, .placeholder {
c.fail_if_immutable(expr.expr)
}
else {

View File

@ -4,18 +4,22 @@ interface Iter<T> {
struct ArrayIter<T> {
data []T
mut:
index int
}
fn (mut i ArrayIter<T>) next<T>() ?T {
if i.data.len == 0 {
return none
}
return i.data[0]
i.index += 1
return i.data[i.index]
}
fn iter<T>(arr []T) Iter<T> {
return ArrayIter<T>{
data: arr
index: 0
}
}
@ -24,5 +28,5 @@ fn test_generics_fn_return_generic_interface() {
println(x)
y := x.next() or { 0 }
println(y)
assert y == 1
assert y == 2
}