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

View File

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