mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generics fn selector expr with unexpected symbol (#10851)
This commit is contained in:
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)
|
||||
}
|
||||
}
|
||||
.aggregate {
|
||||
.aggregate, .placeholder {
|
||||
c.fail_if_immutable(expr.expr)
|
||||
}
|
||||
else {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user