-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
./v test vlib/v/tests/generics_chans_select_test.v fails #20298
Labels
Bug
This tag is applied to issues which reports bugs.
Status: Confirmed
This bug has been confirmed to be valid by a contributor.
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Comments
The test succeeds on FreeBSD-13.2-STABLE, using tcc. It fails when cc is used in place of tcc. |
I can reproduce the same cgen error with clang 16.0.6 on windows too. |
spytheman
added
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Status: Confirmed
This bug has been confirmed to be valid by a contributor.
labels
Dec 29, 2023
It compiles fine with clang 15.0.0 and lower. |
This test case has an error, see the comments in the code: import time
pub type EventListener[T] = fn (T) !
@[heap]
struct Chan[T] {
c chan T
}
pub type Check[T] = fn (T) bool
struct EventWaiter[T] {
check ?Check[T]
c &Chan[T]
}
pub struct EventController[T] {
mut:
id int
wait_fors map[int]EventWaiter[T]
listeners map[int]EventListener[T]
}
fn (mut ec EventController[T]) generate_id() int {
return ec.id++
}
@[params]
pub struct EmitOptions {
pub:
error_handler ?fn (int, IError)
}
pub fn (mut ec EventController[T]) emit(e T, options EmitOptions) {
for i, w in ec.wait_fors {
mut b := false
if w.check != none {
b = (w.check or { panic(err) }) // Here !!!!!!, w.check is a ?fn type, the correct code would be: b = w.check or { panic(err) }(e), The 'e' in the below row should be the call arg here.
e
} else {
b = true
}
if b {
w.c.c <- e
ec.wait_fors.delete(i)
return
}
}
mut ts := []thread{}
for i, l in ec.listeners {
ts << spawn fn [options] [T](f EventListener[T], j int, e T) {
f(e) or {
if g := options.error_handler {
g(j, err)
}
}
}(l, i, e)
}
ts.wait()
}
@[params]
pub struct EventWaitParams[T] {
pub:
check ?Check[T]
timeout ?time.Duration
}
pub struct Awaitable[T] {
id int
timeout ?time.Duration
c Chan[T]
mut:
controller &EventController[T]
}
struct Zero[T] {
e T
}
pub fn (mut a Awaitable[T]) do() ?T {
defer {
a.controller.wait_fors.delete(a.id)
}
if timeout := a.timeout {
mut e := Zero[T]{}.e
select {
e = <-a.c.c {
r := e
return r
}
timeout.nanoseconds() {
return none
}
}
}
return <-a.c.c
}
pub fn (mut ec EventController[T]) wait(params EventWaitParams[T]) Awaitable[T] {
mut c := Chan[T]{}
id := ec.generate_id()
ec.wait_fors[id] = EventWaiter[T]{
check: params.check
c: &mut c
}
return Awaitable[T]{
id: id
timeout: params.timeout
controller: unsafe { &mut ec }
c: c
}
}
struct Foo {}
struct Bar {}
fn main() {
x := EventController[Foo]{}
println(x)
y := EventController[Bar]{}
println(y)
assert true
}
There are 3 issues in this issue:
So there are 3 issues that need to be fixed The root cause is the Parser. |
Simplified: type Fn[T] = fn (arg T) bool
struct Foo[T] {
f ?Fn[T]
}
@[params]
struct Bar {}
fn (mut f Foo[T]) method (arg T) {
mut b := false
if f.f != none {
b = (f.f or { panic(err) })
arg
} else {
b = true
}
if b {
}
}
fn main() {
mut foo := Foo[Bar] {
f: fn (arg Bar) bool {
return true
}
}
foo.method(Bar{})
} |
shove70
added a commit
to shove70/v
that referenced
this issue
Jan 1, 2024
spytheman
pushed a commit
that referenced
this issue
Jan 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug
This tag is applied to issues which reports bugs.
Status: Confirmed
This bug has been confirmed to be valid by a contributor.
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Describe the bug
This is on FreeBSD-14.0-p4. I did a fresh install of v with git clone & gmake. There is a problem wit tcc so I removed thirdparty/tcc. Running the above test fails. Every other test succeeds.
Reproduction Steps
Do a fresh install on a freebsd-14.0 machine (patch number doesn't matter). Make sure
boehm-gc-threaded
pkg is installed. Thengmake
, removethirdparty/gcc
and then run the above test.Expected Behavior
The test should pass.
Current Behavior
See below
Possible Solution
No idea.
Additional Information/Context
V version
V 0.4.3 680b0d4
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: