v
v copied to clipboard
C error when outer struct is not locked
V doctor:
OS: linux, Ubuntu 20.04.4 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
getwd: /home/woody/sources/v/bugs
vmodules: /home/woody/.vmodules
vroot: /home/woody/sources/v/v
vexe: /home/woody/sources/v/v/v
vexe mtime: 2022-07-27 08:53:53
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 9ec8a99.6a7eb82
Git version: git version 2.25.1
Git vroot status: weekly.2022.30-10-g6a7eb82d
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 827f7452
What did you do?
v -g -o vdbg cmd/v && vdbg shared.v
module main
import time
struct Alarms {
mut:
times shared []time.Time
}
fn (shared alarms Alarms) add(alarm time.Time) {
lock alarms.times {
if alarms.times.any(it == alarm) {
return
}
alarms.times << alarm
}
}
fn main() {
shared alarms := Alarms{
times: []time.Time{cap: 10}
}
utc := time.utc()
alarms.add(utc)
}
What did you expect to see?
a compile error in line 11, because alarms is not locked
What did you see instead?
==================
/tmp/v_1000/shared.2802438240981746509.tmp.c:16983: error: struct or union expected
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang