1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add an interface check for mutability, fixes #1081, fixes #7038 (#11963)

This commit is contained in:
Alexander Ivanov
2021-10-11 15:41:31 +03:00
committed by GitHub
parent d0c961ebc0
commit 0386f2bbea
40 changed files with 219 additions and 92 deletions

View File

@@ -10,9 +10,9 @@ fn test_with_cancel() {
// The callers of gen need to cancel the context once
// they are done consuming generated integers not to leak
// the internal routine started by gen.
gen := fn (ctx context.Context) chan int {
gen := fn (mut ctx context.Context) chan int {
dst := chan int{}
go fn (ctx context.Context, dst chan int) {
go fn (mut ctx context.Context, dst chan int) {
mut v := 0
ch := ctx.done()
for {
@@ -26,16 +26,20 @@ fn test_with_cancel() {
}
}
}
}(ctx, dst)
}(mut ctx, dst)
return dst
}
ctx, cancel := context.with_cancel(context.background())
mut background := context.background()
mut b := &background
mut ctx, cancel := context.with_cancel(mut b)
defer {
cancel()
}
ch := gen(ctx)
mut mut_ctx := ctx
mut ctx2 := &mut_ctx
ch := gen(mut ctx2)
for i in 0 .. 5 {
v := <-ch
assert i == v